public static String ToChinese(String str) { //将Unicode字符转换为中文
Pattern p = Pattern.compile("&#([\\d]{4,5});");
Matcher m = p.matcher(str);
StringBuffer b = new StringBuffer();
while (m.find()) {
try {
String ss = m.group(1);
char c = (char) Integer.parseInt(ss);
String s = Character.toString(c);
m.appendReplacement(b, s);
}
catch (Exception ex) {
ex.printStackTrace();
}
}
m.appendTail(b);
return b.toString();
}
将Unicode字符转换成中文
最新推荐文章于 2023-02-15 17:44:32 发布
本文提供了一段Java代码,用于将包含Unicode转义序列的字符串转换成对应的中文字符。通过正则表达式匹配Unicode编码,并将其转换为相应的中文字符。
2627

被折叠的 条评论
为什么被折叠?



