Skip to content

Instantly share code, notes, and snippets.

@backwind1233
Created December 31, 2015 08:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save backwind1233/eb713683c3b59efdc009 to your computer and use it in GitHub Desktop.
Save backwind1233/eb713683c3b59efdc009 to your computer and use it in GitHub Desktop.
unicode 编码中文转换
/**
* 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