</pre><pre name="code" class="java"><span style="font-size:18px;">public static boolean isChar(char c) { //判断中英文 (中:false,英:true)
int k = 0x80;
return c / k == 0 ? true : false;
}
public static int length(String s) { //得到字符串占位,中文2位,英文1位
if (s == null)
return 0;
char[] c = s.toCharArray();
int len = 0;
for (int i = 0; i < c.length; i++) {
len++;
if (!isChar(c[i])) {
len++;
}
}
<span style="white-space: pre;"> </span>return len;
}</span>
java判断中英文占位
最新推荐文章于 2023-06-30 21:24:23 发布