Java判断字符是否是汉字,界限【 19968–171941 】
1. 判断字符是否是中文
/**
* 输入的字符是否是汉字
* @param a char
* @return boolean
*/
public static boolean isChinese(char a) {
int v = (int)a;
return (v >=19968 && v <= 171941);
}
2.判断字符是否是中文
public static boolean containsChinese(String s){
if (null == s || "".equals(s.trim())) return false;
for (int i = 0; i < s.length(); i++) {
if (isChinese(s.charAt(i))) return true;
}
return false;
}
转载。原文地址:Java判断字符是否是汉字
3.判断字符串中是否有中文
有中文返回true
public static boolean isChineseChar(String str){
boolean temp = false;
Pattern p=Pattern.compile("[\u4e00-\u9fa5]");
Matcher m=p.matcher(str);
if(m.find()){
temp = true;
}
return temp;
}