Android examples for java.lang:String Escape
Escape string to create HTML String
import java.net.MalformedURLException; import java.net.URL; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static String toHTMLString(String s) { StringBuffer stringbuffer = new StringBuffer(); for (int i = 0; s != null && i < s.length(); i++) { char c = s.charAt(i); if (c == '\'') // stringbuffer.append("'"); stringbuffer.append(c);/*from w w w . j av a 2s. com*/ else if (c == '"') // stringbuffer.append("""); stringbuffer.append(c); else if (c == '\n') stringbuffer.append("<BR>\n"); else if (c == '\t') stringbuffer.append(" "); else if (c == '<') // stringbuffer.append("<"); stringbuffer.append(c); else if (c == '>') // stringbuffer.append(">"); stringbuffer.append(c); else if (c == '&') stringbuffer.append("&"); else stringbuffer.append(c); } return stringbuffer.toString(); } }