判断字符串中有多少个中文的工具类

public class ChineseNumFromStrUtil {
    public static int getChineseNumFromStrUtil(String str) {
        int count = 0;
        String regEx = "[\\u4e00-\\u9fa5]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        while (m.find()) {
            for (int i = 0; i <= m.groupCount(); i++) {
                count = count + 1;
            }
        }
        return count;
    }
}

 

posted on 2014-10-29 15:08  java界的奥特曼  阅读(337)  评论(0编辑  收藏  举报