做个小程序,没想到在这上面翻车了
STL String.find函数 中文字符占两格
某博主的java解决方案
public static int chineseLength(String value){
int valueLength = 0;
String chinese = “[\u0391-\uFFE5]”;/这是汉语的这则表达式/
for (int i =0; i <value.length() ; i++) {
/* 获取一个字符 /
String temp = value.substring(i, i + 1);
/
判断是否为中文字符 /
if (temp.matches(chinese)) {
/
中文字符长度为2 /
valueLength += 2;
} else {
/
其他字符长度为1 */
valueLength += 1;
}
}
return valueLength;

————————————————
CSDN博主「jackliang」
原文链接https://blog.csdn.net/xiqingchun/article/details/9260725

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
猜你喜欢
  • 2021-09-13
  • 2021-12-12
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案