You should understand what kind of codes the Chinese words are using first, maybe GBcode or UNIcode.for GBcode, if the first byte value >= 0x80, then it's a Chinese word. for Unicode, if the first byte value >= 0x80, then it's a Chinese word.of course, there're many other encoding schema for Chinese words, e.g. GBK, UTF-8 and etc..
String str = new String("..."); str.length(); new String(str.getBytes(),"8859_1").length();
haha, i am coming 2.the up one is quite a answer!so nice, and 0x80 is the kernal ,huh?you have to notice what's the damn ambit of every Chinese character.my regards.
String s = "我是谁"; Pattern p = Pattern.compile("[\u4e00-\u9fa5]+"); Matcher m = p.matcher(s); if(m.find()){ return m.group.equals(s) }
using first, maybe GBcode or UNIcode.for GBcode, if the first byte value >= 0x80, then it's a Chinese word.
for Unicode, if the first byte value >= 0x80, then it's a Chinese word.of course, there're many other encoding schema for Chinese words,
e.g. GBK, UTF-8 and etc..
new String(str.getBytes(),"8859_1").length();
Pattern p = Pattern.compile("[\u4e00-\u9fa5]+");
Matcher m = p.matcher(s);
if(m.find()){
return m.group.equals(s)
}
如果字符串是String s = "abc我是谁";
也一样匹配
char c = testStr.charAt(0);
if (c >= 0x4e00 && c <= 0x9fa5) {
return true; //包含就OK
}
/*
if (c < 0x4e00 || c > 0x9fa5) {
return false; //全部是汉字
}
*/
}