Created
December 31, 2015 08:46
-
-
Save backwind1233/eb713683c3b59efdc009 to your computer and use it in GitHub Desktop.
unicode 编码中文转换
This file contains 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
/** | |
* unicode编码转换为中文 | |
* @param str | |
* @return | |
*/ | |
public static String reconvert(String str) { | |
char[] c = str.toCharArray(); | |
String resultStr = ""; | |
for (int i = 0; i < c.length; i++) | |
resultStr += String.valueOf(c[i]); | |
return resultStr; | |
} | |
/** | |
* 中文转换为unicode | |
* @param str | |
* @return | |
*/ | |
public static String conver(String str) { | |
String result = ""; | |
for (int i = 0; i < str.length(); i++) { | |
String temp = ""; | |
int strInt = str.charAt(i); | |
if (strInt > 127) { | |
temp += "\\u" + Integer.toHexString(strInt); | |
} else { | |
temp = String.valueOf(str.charAt(i)); | |
} | |
result += temp; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment