Java HTML Escape htmlEscape(final String text)

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

Description

Escapes the text into proper HTML, converting characters into character entities when required.

License

Open Source License

Parameter

Parameter Description
text the text to be escaped.

Return

the escaped text.

Declaration

static String htmlEscape(final String text) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*w  w w  .j  a v  a  2s.  c o m*/
     * Escapes the text into proper HTML, converting characters into character entities when required.
     * @param text the text to be escaped.
     * @return the escaped text.
     */
    static String htmlEscape(final String text) {
        return text.replaceAll("&", "&") // replace the ampersand first because it will show up later as part of character entities
                .replaceAll("<", "&lt;").replaceAll(">", "&gt;");
    }
}

Related

  1. escapeHTML(String text)
  2. escapeHTML(String text)
  3. escapeHTMLLine(String line)
  4. escapeHTMLSpecialChars(String aText)
  5. escapeHTMLTagCopy(String text)
  6. htmlEscape(Object obj)
  7. htmlEscape(String html)
  8. htmlescape(String html)
  9. htmlEscape(String input)