「Java」Stringクラスの offsetByCodePoints()で文字を取り出す
関数
public int java.lang.String.offsetByCodePoints(int index, int codePointOffset)
パラメータ:
index – オフセットされるインデックス
codePointOffset – オフセット(コード・ポイント数)
戻り値:
このString内でのインデックス
Javaコード
package com.example;
public class CharArrayDemo {
public static void main(String[] args) {
String target = "関東や東海で危険な暑さ";
for (int i = 0; i < target.length(); i = target.offsetByCodePoints(i, 1)) {
System.out.println(Character.toChars(target.codePointAt(i)));
}
}
}
package com.example;
public class CharArrayDemo {
public static void main(String[] args) {
String target = "関東や東海で危険な暑さ";
for (int i = 0; i < target.length(); i = target.offsetByCodePoints(i, 1)) {
System.out.println(Character.toChars(target.codePointAt(i)));
}
}
}
package com.example; public class CharArrayDemo { public static void main(String[] args) { String target = "関東や東海で危険な暑さ"; for (int i = 0; i < target.length(); i = target.offsetByCodePoints(i, 1)) { System.out.println(Character.toChars(target.codePointAt(i))); } } }
結果
関
東
や
東
海
で
危
険
な
暑
さ
関
東
や
東
海
で
危
険
な
暑
さ
関 東 や 東 海 で 危 険 な 暑 さ