判断字符是否为中文

/**
     * 判断字符是否是中文
     *
     * @param str
     * @return
     * @author YOLANDA
     */
    public boolean isChineseStr(String str) {

        char[] chars = str.toCharArray();
        boolean ischinese = true;
        for (int i = 0; i < chars.length; i++) {
            if (!isChinese(chars[i])) {
                ischinese = false;
                break;
            }

        }
        return ischinese;

    }

    /**
     * 判断字符是否是中文
     *
     * @param c
     * @return
     * @author YOLANDA
     */
    public static 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;
    }

 

posted @ 2020-06-23 13:29  bbqopdd  阅读(244)  评论(0编辑  收藏  举报