0
点赞
收藏
分享

微信扫一扫

获取字符串中的中文字符长度


/**
* 获取字符串中的中文字符长度
* @param str
* @return
*/
public static int getChineseCharacters(String str){
byte chars[]=str.getBytes();
String cc="";
byte temp[]=new byte[2];
for(int i=0, count=0; i<chars.length; i++){
if(chars[i]<0){
temp[count]=chars[i];
count++;
if(count%2==0){
cc+=new String(temp);
count=0;
}
}
}
return cc.length();
}


举报

相关推荐

0 条评论