统计指定内容的汉字个数:
String str = "北京欢迎你 hello welcome!"; int count=0; Pattern pattern = Pattern.compile("[u4e00-u9fa5]"); char c[] = str.toCharArray(); for(int i=0;i<c.length;i++){ Matcher matcher = pattern.matcher(String.valueOf(c[i])); if(matcher.matches()){ count++; } } System.out.println(count);