Here you can find the source of textToHTML(String text)
public static String textToHTML(String text)
//package com.java2s; //License from project: Open Source License public class Main { public static String textToHTML(String text) { if (text == null) { return null; }//w w w . j av a 2 s .co m int length = text.length(); boolean prevSlashR = false; String out = ""; for (int i = 0; i < length; i++) { char ch = text.charAt(i); switch (ch) { case '\r': if (prevSlashR) { out += "<br>"; } prevSlashR = true; break; case '\n': prevSlashR = false; out += "<br>"; break; case '"': if (prevSlashR) { out += "<br>"; prevSlashR = false; } out += """; break; case '<': if (prevSlashR) { out += "<br>"; prevSlashR = false; } out += "<"; break; case '>': if (prevSlashR) { out += "<br>"; prevSlashR = false; } out += ">"; break; case '&': if (prevSlashR) { out += "<br>"; prevSlashR = false; } out += "&"; break; default: if (prevSlashR) { out += "<br>"; prevSlashR = false; } out += ch; break; } } return (out); } }