Here you can find the source of htmlText(String text)
public static String htmlText(String text)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w ww . java 2 s .co m*/ * This method converts texts to be displayed on html-page. Following conversion are done "<" => * "<" , ">" => ">" and "&" => "&", "\n" => "<br> * " */ public static String htmlText(String text) { StringBuilder sb = new StringBuilder(); char c; if (text == null) return ""; for (int i = 0; i < text.length(); i++) { c = text.charAt(i); switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '\"': sb.append("""); break; case '\n': sb.append("<br>"); break; default: sb.append(c); } } return sb.toString(); } }