Java HTML Unescape unEscapeHtml(String text)

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

Description

Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

License

Open Source License

Declaration

public static String unEscapeHtml(String text) 

Method Source Code

//package com.java2s;
/*//  w  ww.j  av a 2 s .  c o  m
 * ***** BEGIN LICENSE BLOCK *****
 * Zimbra Collaboration Suite Server
 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 * ***** END LICENSE BLOCK *****
 */

public class Main {
    /**
     * Unescapes a string containing entity escapes to a string containing the actual Unicode characters
     * corresponding to the escapes.
     */
    public static String unEscapeHtml(String text) {
        if (text == null || text.length() == 0) {
            return "";
        }

        String result = text;
        result = result.replace("&lt;", "<");
        result = result.replace("&gt;", ">");
        result = result.replace("&amp;", "&");
        result = result.replace("&quot;", "\"");
        result = result.replace("&#034;", "\"");
        result = result.replace("&#039;", "\'");

        return result;
    }
}

Related

  1. unescapeHTML(String s)
  2. unescapeHTML(String source)
  3. unescapeHTML(String source)
  4. unescapeHTML(String source, int start)
  5. unescapeHTML(String str)
  6. unescapeHTML(String value)
  7. unescapeHTML(String value)
  8. unescapeHTML2(String source, int start)
  9. unescapeHtmlByName(final String input)