Android examples for android.text:Html
Escape input chars to be shown in html.
import android.content.res.Resources; import java.text.DateFormat; import java.util.Date; public class Main{ /**// w ww.j ava2s. c o m * * * @param input * @return */ public static String escapeHtml(String input) { StringBuilder builder = new StringBuilder(); int pos = 0; int len = input.length(); while (pos < len) { int codePoint = Character.codePointAt(input, pos); if (codePoint == '"') builder.append("""); else if (codePoint == '&') builder.append("&"); else if (codePoint == '<') builder.append("<"); else if (codePoint == '>') builder.append(">"); else if (codePoint == '\n') builder.append("<br />"); else if (codePoint >= 0 && codePoint < 160) builder.append(Character.toChars(codePoint)); else builder.append("&#").append(codePoint).append(';'); pos += Character.charCount(codePoint); } return builder.toString(); } }