转换HTML转义字符串为纯统一code / ASCII [英] Convert HTML-escaped strings to plain Unicode/ASCII
本文介绍了转换HTML转义字符串为纯统一code / ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/994331/java-how-to-de$c$c-html-character-entities-in-java-like-httputility-htmlde$c$c">Java:如何去在Java中code HTML字符实体像HttpUtility.HtmlDe code?
有一个Java / Android的方式转换成HTML转义的字符串(如&放大器; Ouml;
或&放大器;大街
)回到它们的ASCII / UNI code再presentations(如 0
或 SS
)?
is there a Java/Android way to convert HTML-escaped strings (such as Ö
or ß
) back to their ASCII/Unicode representations (such as Ö
or ß
)?
我当然不想做一个简单的字符串替换,并尝试只用所有的HTML转义序列的存在,我想有一个随时可以使用的解决方案?
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?
谢谢!
推荐答案
使用这样的:
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);
}
}
这篇关于转换HTML转义字符串为纯统一code / ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文