Home > Java > JavaBase > Java determines whether it is Chinese

Java determines whether it is Chinese

Release: 2019-11-21 15:15:47
Original
3443 people have browsed it

Java determines whether it is Chinese

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;
    }
Copy after login

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;
    }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template