码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-10-29 16:46:51      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   for   sp   div   log   bs   as   

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;
    }
}

 

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

标签:style   blog   color   for   sp   div   log   bs   as   

原文地址:http://www.cnblogs.com/plf112233/p/4059599.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!