统计指定内容的汉字个数:
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);
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/14322.html