public static String decode(String text)
    {
        StringBuilder res = new StringBuilder(text.length());

        for (int i = 0; i < text.length(); i++)
        {
            char ch = text.charAt(i);
            if (ch == '&') {
              int semi = text.indexOf(';', i);
              if (semi > i) {
                char newch = '&';
                String entity = text.substring(i, semi + 1);
                if (entity.equals("&#36;")) {
                  newch = '$';
                }
                else if (entity.equals("&amp;")) {
                  i = semi;
                }
                if (newch != ch) {
                  ch = newch;
                  i = semi;
                }
              }
            }
            res.append(ch);
        }

        return res.toString();
    }
public static String decode(String text)