Java tutorial
//package com.java2s; public class Main { public static String toHtml(String string) { if (string == null) return ""; string = string.replaceAll("&", "&"); string = string.replaceAll("\"", """); string = string.replaceAll("<", "<"); string = string.replaceAll(">", ">"); // string = string.replaceAll("\r\n", "\n"); string = string.replaceAll("\n", "<br>\n"); string = string.replaceAll("\t", " "); string = string.replaceAll(" ", " "); return string; } }