检测java string变量是否含有中文

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class demo {
static String regEx = "[u4e00-u9fa5]";
static Pattern pat = Pattern.compile(regEx);
public static void main(String[] args) {
String input = "Hell world!";
System.out.println(isContainsChinese(input));
input = "hello world";
System.out.println(isContainsChinese(input));
}
 
public static boolean isContainsChinese(String str)
{
Matcher matcher = pat.matcher(str);
boolean flg = false;
if (matcher.find())    {
flg = true;
}
return flg;
}
View Code


检测一句string里是否含有中文的类,挺简单易学,非原创,转自http://blog.tektea.com/archives/406.html

原文地址:https://www.cnblogs.com/cton/p/3474662.html