您的位置:首页 > 编程语言 > Java开发

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

2013-12-14 20:27 267 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: