//定义 REGEX_CHINESE :
private static String REGEX_CHINESE = "[\u4e00-\u9fa5]";// 中文正则
//调用
boolean b = IsContainChinese("str"); // 返回 true 或者 false
private static boolean IsContainChinese(String str) {
// 有中文则为true
boolean flag=true;
int count = 0;
Pattern p = Pattern.compile(REGEX_CHINESE);
Matcher m = p.matcher(str);
while (m.find()) {
for (int i = 0; i <= m.groupCount(); i++) {
count++;
}
}
if(count==0){
flag=false;
}
return flag;
}

本文介绍了一种用于检测字符串中是否包含中文字符的方法。通过使用正则表达式,该方法能够有效地判断输入的字符串中是否存在中文字符,并返回相应的布尔值结果。
265

被折叠的 条评论
为什么被折叠?



