Java如何迭代字符串的子集?
package org.nhooo.example.text;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
public class IterateSubstringExample {
private static final String text =
"How razorback-jumping frogs can level six piqued gymnasts";
public static void main(String[] args) {
CharacterIterator it = new StringCharacterIterator(text, 4, 27, 5);
//在此循环中,我们仅迭代了在
//上面的StringCharacterIterator。它从4的索引中读取
//字符串,最多27个字符。所以只需要以下内容
//字符串“剃刀跳蛙”"razorback-jumping frogs"
for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
System.out.print(ch);
}
}
}
热门推荐
10 美丽晚霞祝福语简短句
11 最美婆婆生日祝福语简短
12 50多岁生日简短祝福语
13 春节后的祝福语简短
14 导师退休花束祝福语简短
15 妈妈给宝贝祝福语简短
16 订婚新发言简短祝福语
17 同事有趣祝福语大全简短
18 红颜生日祝福语简短独特