Home > Java > JavaBase > body text

Java method to determine whether a character is a Chinese character

Release: 2019-12-06 16:48:52
Original
2761 people have browsed it

Java method to determine whether a character is a Chinese character

1. The encoding range of Chinese characters: [\u4e00-\u9fa5] (Recommended java related video tutorials: java video tutorial)

The following method determines whether a character is a Chinese character

//如果是一个汉字返回true,否则返回falsepublic static boolean checkCharCN(char c){
        String s = String.valueOf(c);
        String  regex = "[\u4e00-\u9fa5]";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(s);
        return m.matches();
    }
Copy after login

Java uses Unicode encoding. The range of char type variables is 0-65535. The unsigned value can represent 65536 characters. Basically, characters on the earth can be All including

Chinese characters are basically concentrated between [19968, 40869], 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 ])

Capital letters: [0x41,0x5a] (or decimal [65, 90])

For more java related articles, please pay attention to the java basic tutorial column.

The above is the detailed content of Java method to determine whether a character is a Chinese character. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!