Determine whether there is Chinese:
public boolean checkcountname(String countname) { Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); Matcher m = p.matcher(countname); if (m.find()) { return true; } return false; }
Determine whether the entire string is composed of Chinese:
public boolean checkname(String name) { int n = 0; for(int i = 0; i < name.length(); i++) { n = (int)name.charAt(i); if(!(19968 <= n && n <40869)) { return false; } } return true; }
Java uses Unicode encoding char type variables The range is 0-65535. The unsigned value can represent 65536 characters. Basically, all characters on the earth can be included.
Chinese characters are basically concentrated between [19968, 40869], with a total of 20901 Chinese characters
unicode encoding range:
Chinese characters: [0x4e00,0x9fa5] (or decimal [19968,40869])
Numbers: [0x30,0x39] (or decimal [48, 57])
Lowercase letters: [0x61,0x7a] (or decimal [97, 122])
Uppercase letters: [0x41,0x5a] (or decimal [65, 90])
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of Java determines whether it is Chinese. For more information, please follow other related articles on the PHP Chinese website!