接口定义文档将汉字作2个字符时, 正确截取汉字的方法.

public static void main(String[] ar){
String s = “我1天才222啊”;
int[] lens = new int[]{2, 1, 4, 3, 2};
int sum = 0;
for (int i = 0; i < lens.length; i++) {
int len = lens
System.out.println(new String(s.getBytes(), sum, len));
sum += len; 


}

Tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *