Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert HTML-escaped strings to plain Unicode/ASCII [duplicate]

Tags:

java

html

android

Possible Duplicate:
Java: How to decode HTML character entities in Java like HttpUtility.HtmlDecode?

is there a Java/Android way to convert HTML-escaped strings (such as Ö or ß) back to their ASCII/Unicode representations (such as Ö or ß)?

I of course do not want to do a simple string-replacement and try with just every HTML-escape-sequence that exists, I'd guess there is a ready-to use solution?

Thanks!

like image 966
Elmi Avatar asked Dec 09 '12 17:12

Elmi


1 Answers

Use this:

import org.apache.commons.lang.StringEscapeUtils;

public class StringEscapeUtilsTrial {
public static void main(String[] args) {
    String strHTMLInput = "<p>MyName<p>";
    String strEscapeHTML = StringEscapeUtils.escapeHtml(strHTMLInput);
    String strUnEscapeHTML = StringEscapeUtils.unescapeHtml(strEscapeHTML);
    System.out.println("Escaped HTML >>> " + strEscapeHTML);
    System.out.println("UnEscaped HTML >>> " + strUnEscapeHTML);
    }
}
like image 157
Harish Raj Avatar answered Oct 19 '22 08:10

Harish Raj