public static int byteNum(String str) { int m = 0; char arr[] = str.toCharArray(); for(int i=0;i<arr.length;i++) { char c = arr[i]; if((c >= 0x0391 && c <= 0xFFE5)) //中文字符 { m = m + 2; } else if((c>=0x0000 && c<=0x00FF)) //英文字符 { m = m + 1; } } return m; }