gpt4 book ai didi

Java,如何通过移位拆分字符串

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:14:16 25 4
gpt4 key购买 nike

如何使用 shifting 将字符串拆分为 2 个字符。例如;

我的字符串是 = todayiscold

我的目标是:"to","od","da","ay","yi","is","sc","co","ol","ld"

但使用此代码:

Arrays.toString("todayiscold".split("(?<=\\G.{2})")));

我得到:`"to","da","yi","co","ld"

有人帮忙吗?

最佳答案

试试这个:

        String e = "example";
for (int i = 0; i < e.length() - 1; i++) {
System.out.println(e.substring(i, i+2));
}

关于Java,如何通过移位拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17999233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com