获取字符串字节数方法
//获取字符串字节方法1
public static int getWordCount(String s) {
int length = 0;
for (int i = 0; i < s.length(); i++) {
int ascii = Character.codePointAt(s, i);
if (ascii >= 0 && ascii <= 255)
length++;
else
length += 2;
}
return length;
}
//获取字符串字节方法2 正则表达式
public static int getWordCount2(String s) {
s = s.replaceAll("[^\\x00-\\xff]", "**");
int length = s.length();
return length;
}

浙公网安备 33010602011771号