Here you can find the source of HTMLEnc(String s)
public static String HTMLEnc(String s)
//package com.java2s; public class Main { /**//from w ww . j av a 2 s . co m * HTML encoding (does not convert line breaks). * Replaces all '>' '<' '&' and '"' with entity reference */ public static String HTMLEnc(String s) { return XMLEncNA(s); } /** * XML encoding without replacing apostrophes. * @see #XMLEnc(String) */ public static String XMLEncNA(String s) { int ln = s.length(); for (int i = 0; i < ln; i++) { char c = s.charAt(i); if (c == '<' || c == '>' || c == '&' || c == '"') { StringBuffer b = new StringBuffer(s.substring(0, i)); switch (c) { case '<': b.append("<"); break; case '>': b.append(">"); break; case '&': b.append("&"); break; case '"': b.append("""); break; } i++; int next = i; while (i < ln) { c = s.charAt(i); if (c == '<' || c == '>' || c == '&' || c == '"') { b.append(s.substring(next, i)); switch (c) { case '<': b.append("<"); break; case '>': b.append(">"); break; case '&': b.append("&"); break; case '"': b.append("""); break; } next = i + 1; } i++; } if (next < ln) b.append(s.substring(next)); s = b.toString(); break; } // if c == } // for return s; } }