Java HTML Escape htmlEscape(String text)

Here you can find the source of htmlEscape(String text)

Description

Performs necessary escaping to render arbitrary plain text as plain text without any markup.

License

CDDL license

Declaration

public static String htmlEscape(String text) 

Method Source Code

//package com.java2s;
//License from project: CDDL license 

public class Main {
    /**//from  w  w w  . j  a va2s  .co m
     * Performs necessary escaping to render arbitrary plain text as plain text without any markup.
     */
    public static String htmlEscape(String text) {
        StringBuilder buf = new StringBuilder(text.length() + 64);
        for (int i = 0; i < text.length(); i++) {
            char ch = text.charAt(i);
            if (ch == '<')
                buf.append("&lt;");
            else if (ch == '&')
                buf.append("&amp;");
            else
                buf.append(ch);
        }
        return buf.toString();
    }
}

Related

  1. htmlEscape(String str)
  2. htmlEscape(String str)
  3. htmlEscape(String str)
  4. htmlEscape(String string)
  5. htmlEscape(String tag)
  6. htmlescapeAll(String s1)
  7. htmlEscapeBasicMarkup(final String text)
  8. HTMLEscapeBr(String original)
  9. htmlEscapeSpace(String uri)