Tuesday, May 22, 2012

JAVA regular expression, encode &#[0-9]+ form html

private static String ReplceSpecialChars(String s) {
        String orig=s;
        Pattern pnum=Pattern.compile("&#([0-9]+);");
        Matcher m=pnum.matcher(s);
        while(m.find())
        {
            int t=Integer.parseInt(m.group(1));
            char ch=(char)t;
            orig=orig.replaceFirst(m.group(0), ""+ch);
        }
        return orig;
    }

CàT will be parsed to CàT
CàáT , will be CàáT

No comments:

 
Locations of visitors to this page