Here you can find the source of toHTML(String org, boolean inputValue)
public static String toHTML(String org, boolean inputValue)
//package com.java2s; //License from project: Open Source License public class Main { public static String toHTML(String org, boolean inputValue) { StringBuffer result = new StringBuffer(org.length()); char[] chars = org.toCharArray(); for (int i = 0; i < chars.length; i++) { if (chars[i] == '\"') result.append("""); else if (chars[i] == '<') result.append("<"); else if (chars[i] == '>') result.append(">"); else if (chars[i] == '&') result.append("&"); else if (chars[i] == '\r') { if (inputValue) result.append(chars[i]); else { result.append("<br/>"); if (i + 1 < chars.length && chars[i + 1] == '\n') i++;//from w w w.j av a 2s . c o m } } else if (chars[i] == '\n') { if (inputValue) result.append(chars[i]); else result.append("<br/>"); } else if (chars[i] == ' ') if (inputValue) result.append(chars[i]); else result.append(" "); else result.append(chars[i]); } return result.toString(); } public static String toHTML(String org) { return toHTML(org, false); } }