1、方法一
- char c = 'a';
- if((c >= 0x4e00)&&(c <= 0x9fbb)) {
- System.out.println("是中文");
- }
上面的方法很简单,但只能判断是否是中文,但不能判断是否是中文标点。
下面的方法很全面,中文字符标点都可以判断
2、方法二
- 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;
- }
评论
|| block == CJK_COMPATIBILITY_IDEOGRAPHS // 中日韩兼容字符
|| block == CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A // 中日韩统一表意文字扩充A
|| block == GENERAL_PUNCTUATION // 一般标点符号, 判断中文的“号
|| block == CJK_SYMBOLS_AND_PUNCTUATION // 符号和标点, 判断中文的。号
|| block == HALFWIDTH_AND_FULLWIDTH_FORMS // 半角及全角字符, 判断中文的,号