本文实例讲述了java统计汉字字数的方法。分享给大家供大家参考,具体如下:

public class TongJiHanZi {
public static int count(String text) {
String Reg="^[\u4e00-\u9fa5]{1}$";//正则
int result=0;
for(int i=0;i
String b=Character.toString(text.charAt(i));
if(b.matches(Reg))result++;
}
return result;
}
public static void main(String[] args) {
String text = "汉字汉字仮名かなカナ 0189 azAZ ./ ";
System.out.println(count(text));
}
}

PS:这里再为大家推荐2款非常方便的统计工具供大家参考使用:

在线字数统计工具:http://tools.jb51.net/code/zishutongji

在线字符统计与编辑工具:http://tools.jb51.net/code/char_tongji