如何在Java中将HTML转换为UTF-8 [英] How to convert from HTML to UTF-8 in java

查看:186
本文介绍了如何在Java中将HTML转换为UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASCII字符串,带有HTML实体,如:

 & agrave; 
& uml;
& ccedil;

我需要这个String没有这些实体并将它们转换为UTF-8字符。
有什么简单的方法,在java中做到这一点?



其中:

  Clazz.method(a& agrave;,UTF-8)

返回aà



或类似的内容? 看看 org.apache.commons.lang.StringEscapeUtils.unescapeHtml(...)。显然它理解HTML 4中定义的所有字符实体。


I have an ASCII String, with HTML entities, like:

 à
 ¨
 ç

I need this String to be without those entities and convert them into UTF-8 chars. Is there any easy way, in java to do that?

Where:

 Clazz.method("aà","UTF-8")

returns "aà"

or something like that?

解决方案

Take a look at org.apache.commons.lang.StringEscapeUtils.unescapeHtml(...). Apparently it understands all character entities defined in HTML 4.

这篇关于如何在Java中将HTML转换为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆