Java tutorial
//package com.java2s; public class Main { public static String replaceEntities(String s) { StringBuilder sb = new StringBuilder(s); int len = s.length(); int skip = 0; int iSkip = 0; for (int i = 0; i < len; i++) { iSkip = i + skip; char c = sb.charAt(iSkip); if (c == '&') { sb.replace(iSkip, iSkip + 1, "&"); skip += 4; } else if (c == '\'') { sb.replace(iSkip, iSkip + 1, "'"); skip += 5; } else if (c == '<') { sb.replace(iSkip, iSkip + 1, "<"); skip += 3; } else if (c == '>') { sb.replace(iSkip, iSkip + 1, ">"); skip += 3; } else if (c == '"') { sb.replace(iSkip, iSkip + 1, """); skip += 5; } } return sb.toString(); } }