Skip to content

Instantly share code, notes, and snippets.



Last active Jul 13, 2017
What would you like to do?
[Java 汉字记数] 利用正则表达式完成 #java
public static int hanStrCount(String hanStr){
int count = 0;
for (int i = 0; i < hanStr.length(); i++) {
boolean matches = Pattern.matches("^[\u4E00-\u9FA5]{0,}$",String.valueOf(hanStr.charAt(i)));
if (matches) count++;
return count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment