Home  >  Article  >  Java  >  Java method to determine whether a character is a Chinese character

Java method to determine whether a character is a Chinese character

尚
Original
2019-11-26 10:28:022776browse

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();
    }

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!

Statement:
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