Java tutorial
//package com.java2s; public class Main { private static final int ESCAPED_CODE_MAX_SIZE = 10; private static String unescapeControlCodes(String text) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (c == '&' && i + 1 < text.length() && text.charAt(i + 1) == '#') { int semiColonIndex = semiColonIndex(text, i); if (semiColonIndex != -1) { int value = Integer.valueOf(text.substring(i + 2, semiColonIndex)); builder.append((char) value); i = semiColonIndex; } } else { builder.append(c); } } return builder.toString(); } private static int semiColonIndex(String text, int fromPos) { int semiColonIndex = -1; int j = 1; do { if (j > ESCAPED_CODE_MAX_SIZE) break; if (text.charAt(fromPos + j) == ';') { semiColonIndex = fromPos + j; break; } j++; } while (true); return semiColonIndex; } }