Java examples for java.lang:String HTML
Converts ASCII text to HTML
//package com.java2s; public class Main { /**/*from w ww .j a va 2 s .co m*/ * Converts ASCII text to HTML * * @param text * @param replacement * @param pre * @return HTML String */ public static String AsciiToHtml(String text, String replacement, boolean pre) { if (text == null) return null; if (replacement == null) replacement = ""; final String tabString = " "; boolean space = false; StringBuffer buffer = new StringBuffer(); for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); switch (ch) { case ' ': buffer.append((pre || !space) ? ' ' : " "); space = true; break; case '\n': buffer.append(replacement); space = false; break; case '&': buffer.append("&"); space = false; break; case '\t': buffer.append(tabString); space = false; break; case '<': buffer.append("<"); space = false; break; case '>': buffer.append(">"); space = false; break; default: buffer.append(ch); space = false; break; } } return buffer.toString(); } }