JAVA 把十六进制Unicode编码字符串转换为中文字符串

时间:2021-06-26 07:47:29
/**
* 把十六进制Unicode编码字符串转换为中文字符串
*/
public static String unicodeToString(String str) {
Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
Matcher matcher = pattern.matcher(str);
char ch;
while (matcher.find()) {
ch = (char) Integer.parseInt(matcher.group(2), 16);
str = str.replace(matcher.group(1), ch + "");
}
return str;
}