Java examples for java.lang:String HTML
This method is used to insert HTML block dynamically
//package com.java2s; public class Main { /**// www.ja va 2 s .c o m * This method is used to insert HTML block dynamically * * @param source the HTML code to be processes * @param bReplaceNl if true '\n' will be replaced by <br> * @param bReplaceTag if true '<' will be replaced by < and * '>' will be replaced by > * @param bReplaceQuote if true '\"' will be replaced by " */ public static String formatHtml(String source, boolean bReplaceNl, boolean bReplaceTag, boolean bReplaceQuote) { StringBuffer sb = new StringBuffer(); int len = source.length(); for (int i = 0; i < len; i++) { char c = source.charAt(i); switch (c) { case '\"': if (bReplaceQuote) sb.append("""); else sb.append(c); break; case '<': if (bReplaceTag) sb.append("<"); else sb.append(c); break; case '>': if (bReplaceTag) sb.append(">"); else sb.append(c); break; case '\n': if (bReplaceNl) { if (bReplaceTag) sb.append("<br>"); else sb.append("<br>"); } else { sb.append(c); } break; case '\r': break; case '&': sb.append("&"); break; default: sb.append(c); break; } } return sb.toString(); } }