Java 判断一个字符串中有几个汉字

public static void main(String[] args) {
int count = 0;
String regEx = "[\\u4e00-\\u9fa5]";
String str = "AQWASD我们都是好孩子AAAA11222 ";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
while (m.find()) {
for (int i = 0; i <= m.groupCount(); i++) {
count = count + 1;
}
}
System.out.println("共有 " + count + "个 ");
}

}

posted @ 2019-04-12 13:33  闲有余日~~正可学问  阅读(3881)  评论(0)    收藏  举报