public String unescapeUnicode(String str){
StringBuffer c = new StringBuffer();
Matcher m = Pattern.compile("\\\\u([0-9a-fA-F]{4})").matcher(str);
while(m.find()) {
StringBuffer b = new StringBuffer();
b.append((char)Integer.parseInt(m.group(1),16));
m.appendReplacement(c, b.toString());
}
m.appendTail(c);
return c.toString();
}
本文介绍了一种使用正则表达式和Java内置方法解析包含Unicode转义序列的字符串的技术。通过实例演示如何将转义的Unicode字符转换为实际的字符。

168

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



