Here you can find the source of toHtml(String str)
public static String toHtml(String str)
//package com.java2s; //License from project: Apache License public class Main { public static String toHtml(String str) { if (str == null) return ""; StringBuffer sb = new StringBuffer(); int len = str.length(); for (int i = 0; i < len; i++) { char c = str.charAt(i); switch (c) { case ' ': sb.append(" "); break; case '\n': sb.append("<br>"); break; case '\r': break; case '\'': sb.append("'"); break; case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '"': sb.append("""); break; case '\\': sb.append("\"); break; default: sb.append(c);/* w ww . j a v a 2s . co m*/ } } return sb.toString(); } }