- public class UnicodeTest {
-
- private static Pattern pattern = Pattern.compile("\\&\\#(\\d+)");
-
-
- public static void main(String[] args) throws UnsupportedEncodingException {
- String str ="业务响应V3.0>缴费、充值>充值不成功>接入充值电话不成功>充值不成功";
-
-
- System.out.println(tr(str));
- }
-
- public static String tr(String str){
- str = str.replaceAll(">", ">");<span style="font-family: Arial, Helvetica, sans-serif;"> //这里的& 和gt显示不出来自动换成了> </span>
- StringBuilder sb = new StringBuilder();
- String[] childs = str.split(";");
- for(String child : childs){
- if(child.contains("&#")){
- Matcher m =pattern.matcher(child);
- while (m.find())
- sb.append((char)Integer.valueOf(m.group(1)).intValue());
-
- }else
- sb.append(child);
- }
- return sb.toString();
- }
-
- }
复制代码 |
|