Java tutorial
//package com.java2s; public class Main { public static String htmlEncode(String s) { StringBuffer stringbuffer = new StringBuffer(); int j = s.length(); for (int i = 0; i < j; i++) { char c = s.charAt(i); switch (c) { case 60: stringbuffer.append("<"); break; case 62: stringbuffer.append(">"); break; case 38: stringbuffer.append("&"); break; case 34: stringbuffer.append("""); break; case 169: stringbuffer.append("©"); break; case 174: stringbuffer.append("®"); break; case 165: stringbuffer.append("¥"); break; case 8364: stringbuffer.append("€"); break; case 8482: stringbuffer.append("™"); break; case 13: if (i < j - 1 && s.charAt(i + 1) == 10) { stringbuffer.append("<br>"); i++; } break; case 32: if (i < j - 1 && s.charAt(i + 1) == ' ') { stringbuffer.append(" "); i++; break; } default: stringbuffer.append(c); break; } } return new String(stringbuffer.toString()); } }