java 怎么把unicode转中文
2016-09-11
展开全部
/**
* @Title: decodeUnicode<br>
* @param dataStr 汉字转化为Unicode后的字符串<br>
* @return String Unicode码转化为的汉字<br>
* @throws <br>
* @dateTime 2016-9-11 上午10:50:48<br>
* @Description: 将Unicode码转为汉字<br>
*/
public static String decodeUnicode(final String dataStr) {
int start = 0;
int end = 0;
final StringBuffer buffer = new StringBuffer();
while (start > -1) {
end = dataStr.indexOf("\\u", start + 2);
String charStr = "";
if (end == -1) {
charStr = dataStr.substring(start + 2, dataStr.length());
} else {
charStr = dataStr.substring(start + 2, end);
}
char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
buffer.append(new Character(letter).toString());
start = end;
}
return buffer.toString();
}
* @Title: decodeUnicode<br>
* @param dataStr 汉字转化为Unicode后的字符串<br>
* @return String Unicode码转化为的汉字<br>
* @throws <br>
* @dateTime 2016-9-11 上午10:50:48<br>
* @Description: 将Unicode码转为汉字<br>
*/
public static String decodeUnicode(final String dataStr) {
int start = 0;
int end = 0;
final StringBuffer buffer = new StringBuffer();
while (start > -1) {
end = dataStr.indexOf("\\u", start + 2);
String charStr = "";
if (end == -1) {
charStr = dataStr.substring(start + 2, dataStr.length());
} else {
charStr = dataStr.substring(start + 2, end);
}
char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
buffer.append(new Character(letter).toString());
start = end;
}
return buffer.toString();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询