Android examples for java.lang:String Escape
Escape Html string
import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.net.URLEncoder; import java.security.SecureRandom; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Locale; public class Main{ public static String checkHtmlView(String strString) { String strNew = ""; try {//w ww . j a va 2s .c om 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; } }