首页 > 代码库 > 【java】java中判断一个字符是否包含汉字,包含汉语标点
【java】java中判断一个字符是否包含汉字,包含汉语标点
public class Text {
//java 一个字符判断全部是中文包括标点符号
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;
}
public static void main(String[] args) {
System.out.println(isChinese(‘?‘));
System.out.println(isChinese(‘!‘));
System.out.println(isChinese(‘,‘));
System.out.println(isChinese(‘。‘));
System.out.println(isChinese(‘;‘));
System.out.println(isChinese(‘留‘));
}
}
【java】java中判断一个字符是否包含汉字,包含汉语标点