Java tutorial
//package com.java2s; public class Main { static public String quotByEntity(String str) { if (str.indexOf('&') != -1) { int len = str.length(); StringBuffer sb = new StringBuffer(len + 4 * 10); int offset = 0; int pos; // while( (pos=str.indexOf('<',offset)) != -1 && offset < len ) do { if ((pos = str.indexOf('&', offset)) == -1) { sb.append(str.substring(offset)); break; } sb.append(str.substring(offset, pos)); sb.append("&"); offset = pos + 1; } while (offset < len); str = sb.toString(); } if (str.indexOf('<') != -1) { int len = str.length(); StringBuffer sb = new StringBuffer(len + 3 * 10); int offset = 0; int pos; // while( (pos=str.indexOf('<',offset)) != -1 && offset < len ) do { if ((pos = str.indexOf('<', offset)) == -1) { sb.append(str.substring(offset)); break; } sb.append(str.substring(offset, pos)); sb.append("<"); offset = pos + 1; } while (offset < len); str = sb.toString(); } return str; } }