原理:根据字符串字节的长度和字符串的长度对比
public boolean hasChinese(String str) { if (StringUtils.isEmpty(str)) { return false; } //1个英文一个字节,1个 中文2个字节(GBK) if (str.getBytes().length == str.length()) { return false; //全是英文 } else { return true; } }
原理:根据字符串字节的长度和字符串的长度对比
public boolean hasChinese(String str) { if (StringUtils.isEmpty(str)) { return false; } //1个英文一个字节,1个 中文2个字节(GBK) if (str.getBytes().length == str.length()) { return false; //全是英文 } else { return true; } }