中日韩等字符占2个字节,英文数字等占1个字节
public static int getStrByteLen(String name){
char[] chars = name.toCharArray();
int len = 0;
for (int i = 0; i < chars.length; i++) {
int k = 0x80;
if (chars[i] / k == 0){//判断一个字符是Ascill字符还是其它字符(如汉,日,韩文字符)
len += 1;
} else{
len += 2;
}
}
return len;
}