判断中文

package com.han.util;

/**
 * Class note: Created by Gaowen on 14-1-12.
 */
@SuppressWarnings("unused")
public class JudgeChinese {
    /**
     * GENERAL_PUNCTUATION 判断中文的“号
     * CJK_SYMBOLS_AND_PUNCTUATION 判断中文的。号
     * HALFWIDTH_AND_FULLWIDTH_FORMS 判断中文的,号
     *
     * @param c -- the character to be judged
     * @return -- true if the character is Chinese; false, otherwise.
     */
    public static boolean isChinese(char c) {
        Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
        return 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;
    }

    public static boolean containsChinese(String strName) {
        char[] chs = strName.toCharArray();
        for (char c : chs) {
            if (isChinese(c)) return true;
        }
        return false;
    }
}

你可能感兴趣的:(判断中文)