1, Method one
Java code
- char c = ' a ';
- if ((c >= 0x4e00) && (c <= 0x9fbb)) {
- System.out.println ("is Chinese");
- }
The above method is simple, but can only judge whether it is Chinese, but can not determine whether it is Chinese punctuation.
The following method is comprehensive, the Chinese character punctuation can be judged
2. Method Two
Java code
- Private Static final boolean Ischinese (char c) {
- Character.unicodeblock UB = Character.UnicodeBlock.of (c);
- if (UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
- || UB = = Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
- || UB = = Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
- || UB = = Character.UnicodeBlock.GENERAL_PUNCTUATION
- || UB = = Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
- || UB = = Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
- return true;
- }
- return false;
- }
Reviews 1 Floor jetmah 2012-06-20 block = = cjk_unified_ideographs//CJK Unified Ideographs
|| Block = = cjk_compatibility_ideographs//CJK Compatible characters
|| Block = = cjk_unified_ideographs_extension_a//CJK Unified Ideographs Extension A
|| Block = = general_punctuation//General punctuation, judging Chinese "No.
|| Block = = cjk_symbols_and_punctuation//symbols and punctuation, judging the Chinese. No.
|| Block = = halfwidth_and_fullwidth_forms//half-width and full-width characters, judging the Chinese, number
Several ways to determine whether Char is Chinese in Java