Android examples for java.lang:String HTML
escape Html tag to create new string
import android.text.Html; import android.text.TextUtils; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main{ private static String escapeHtml(final String text) { if (text == null) { return ""; }//from w w w . jav a 2 s . co m StringBuilder out = new StringBuilder(); int length = text.length(); for (int i = 0; i < length; i++) { char c = text.charAt(i); if (c == '<') { out.append("<"); } else if (c == '>') { out.append(">"); } else if (c == '&') { out.append("&"); } else if (c > 0x7E || c < ' ') { out.append("&#").append((int) c).append(";"); } else if (c == ' ') { while (i + 1 < length && text.charAt(i + 1) == ' ') { out.append(" "); i++; } out.append(' '); } else { out.append(c); } } return out.toString(); } }