您的位置:首页 > 其它

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

2017-10-17 17:42 337 查看
/**
* 获取字符串中的中文字符长度
* @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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: