1 /** 2 * 3 * @param 字符串 4 * @return 字符长度 5 */ 6 public int getWordCount(String str) { 7 int length = 0; 8 for (int i = 0; i < str.length(); i++) { 9 int ascii = Character.codePointAt(str, i); 10 if (ascii >= 0 && ascii <= 255) { 11 length++; 12 } else { 13 length += 2; 14 } 15 } 16 return length; 17 }
时间: 2024-12-19 07:41:26