|
时 间 记 忆 |
<< < 2018 - 7 > >>
日 |
一 |
二 |
三 |
四 |
五 |
六 |
|
|
|
|
|
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
|
|
|
|
|
|
|
|
|
|
java 判断字符串是否乱码是否中文 |
[ 2017-7-3 15:43:00 | By: 我家超超会发光 ] |
/** * @Title: isChinese * 概述:判断字符串是否中文 * @param @param c * @param @return * @return boolean * @author 张爱军 2017-7-3下午03:44:46 * @throws */ 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; } /** * @Title: isMessyCode * 概述:判断字符串是否乱码 * @param @param strName * @param @return * @return boolean * @author 张爱军 2017-7-3下午03:44:24 * @throws */ public static boolean isMessyCode(String strName){ 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(); float chLength = ch.length; float count = 0; for (int i = 0; i < ch.length; i++) { char c = ch[i]; if (!Character.isLetterOrDigit(c)) { if (!isChinese(c)) { count = count + 1; } } } float result = count / chLength; if (result > 0.4) { return true; } else { return false; } } |
|
|
|
|