//判断字符串是否为乱码 protected boolean isMessyCode(String strName) { try { Pattern p = Pattern.compile("\\s*|\t*|\r*|\n*"); Matcher m = p.matcher(strName); String after = m.replaceAll(""); String temp = after.replaceAll("\\p{P}", ""); char[] ch = temp.trim().toCharArray(); int length = (ch != null) ? ch.length : 0; for (int i = 0; i < length; i++) { char c = ch[i]; if (!Character.isLetterOrDigit(c)) { String str = "" + ch[i]; if (!str.matches("[\u4e00-\u9fa5]+")) { return true; } } } } catch (Exception e) { e.printStackTrace(); } return false; }
java用于判断是否为乱码
最新推荐文章于 2024-08-20 04:44:37 发布