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; }
检测一句string里是否含有中文的类,挺简单易学,非原创,转自http://blog.tektea.com/archives/406.html