Created
January 14, 2014 08:06
-
-
Save zhangyangjing/8414811 to your computer and use it in GitHub Desktop.
android utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 判断是否是中文 | |
private 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; | |
} | |
// 半角转化为全角的方法 | |
private String ToSBC(String input) { | |
char[] c = input.toCharArray(); | |
for (int i = 0; i < c.length; i++) { | |
if (c[i] == 32) { | |
c[i] = (char) 12288; | |
continue; | |
} | |
if (c[i] < 127 && c[i]>32) | |
c[i] = (char) (c[i] + 65248); | |
} | |
return new String(c); | |
} | |
// 全角转化为半角的方法 | |
private String ToDBC(String input) { | |
char[] c = input.toCharArray(); | |
for (int i = 0; i < c.length; i++) { | |
if (c[i] == 12288) { | |
c[i] = (char) 32; | |
continue; | |
} | |
if (c[i] > 65280 && c[i] < 65375) | |
c[i] = (char) (c[i] - 65248); | |
} | |
return new String(c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment