/**
* 判断字符串是否包含有中文
* 利用中文或中文标点占两个字节判断
* @param s
* @return
*/
public static boolean isContainChinese(String s) {
try {
return s.length() != s.getBytes("GBK").length;
} catch (Exception e) {
return false;
}
}
/**
* 利用正则判断(无法判断中文标点符号)
* @param s
* @return
*/
public static boolean isContainChinese(String s) {
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(s);
return m.find();
}
java字符串判断是否有中文(包涵中文标点)
最新推荐文章于 2024-04-30 17:28:01 发布