Java中4字节的字符处理案例

String str = "abc我们?";

 

int charNums = str.codePointCount(0, str.length());

System.out.println(charNums);//6

for(int i=0;i<charNums;i++) {

    char[] chars = Character.toChars(str.codePointAt(i));

    System.out.print(new String(chars)+";");

}//a;b;c;我;们;?;

System.out.println();

 

System.out.println(str.length());//7

for(int i=0;i<str.length();i++) {

    System.out.print(str.charAt(i)+";");

}//a;b;c;我;们;?;?;


版权声明:本文为dabing4455原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。