JAvaは文字化けしかどうかを判断するために用いられる

2972 ワード

//          
protected boolean isMessyCode(String strName) {
    try {
        Pattern p = Pattern.compile("\\s*|\t*|\r*|
*"); 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; }