Java examples for java.lang:String HTML
Escape String for Html
//package com.java2s; public class Main { public static void main(String[] argv) { String strString = "java2s.com"; System.out.println(checkHtmlView(strString)); }/*from w ww.j a v a2 s . com*/ public static String checkHtmlView(String strString) { String strNew = ""; try { StringBuffer strTxt = new StringBuffer(""); char chrBuff; int len = strString.length(); for (int i = 0; i < len; i++) { chrBuff = (char) strString.charAt(i); switch (chrBuff) { case '<': strTxt.append("<"); break; case '>': strTxt.append(">"); break; case '"': strTxt.append("""); break; case 10: strTxt.append("<br>"); break; case ' ': strTxt.append(" "); break; //case '&' : //strTxt.append("&"); //break; default: strTxt.append(chrBuff); } } strNew = strTxt.toString(); } catch (Exception ex) { return null; } return strNew; } }