将字符串中&#xxx;字符集替换成文字
方法
代码如下(示例):
public static String decodeUnicode(String str) {
if (!str.contains("&#"))return str;
String[] count = str.split("&#");
StringBuffer sb = new StringBuffer();
String[] split = str.split(";");
for (int i = 0; i < split.length; i++) {
String s=split[i];
char c;
if (s.contains("&#")){
int index = s.indexOf("&#");
if (index==0){
//没有其他数字
s = s.replaceAll("(&#)|;", "");
c = (char) Integer.parseInt(s);
sb.append(c);
}else {
String[] split1 = s.split("&#");
sb.append(split1[0]);
c = (char) Integer.parseInt(split1[1]);
sb.append(c);
}
}
}
return sb.toString();
}