判断字符串是否是乱码 /** * 判断字符串是否是乱码 * * @param strName * 字符串 * @return 是否是乱码 */public static boolean isMessyCode(String strName) {String temp = strName.replaceAll("[0-9a-zA-Z\\p{P}\\s]", "");/
/** * 判断字符串是否是乱码 * * @param strName * 字符串 * @return 是否是乱码 */ public static boolean isMessyCode(String strName) { String temp = strName.replaceAll("[0-9a-zA-Z\\p{P}\\s]", ""); // System.out.println(temp); char[] ch = temp.toCharArray(); for (int i = 0; i < ch.length; i++) { char c = ch[i]; if (!isChinese(c)) { System.out.println(i + "" + temp.charAt(i) + "is not chinese"); return true; } else { // System.out.println(i + "" + temp.charAt(i) + "is a chinese"); } } return false; } /** * 判断字符是否是中文 * * @param c * 字符 * @return 是否是中文 */ 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; }