Android字符串编码和html实体转换

问题描述 投票:15回答:2

Android Java中有一个字符串。如何将其更改为另一种给定的编码,并用&替换HTML实体,例如&

这样可以正确显示国际符号。

android html encoding entities
2个回答
44
投票

解码HTML字符串,您可以使用Html.fromHtml()

like

Html.fromHtml((String) htmlCode).toString();

如果您想反向

您不能使用TextUtils.htmlEncode()


1
投票

您可以添加后缀:

implementation group: 'org.apache.commons', name: 'commons-text', version: '1.3'

并使用StringEscapeUtils.unescapeHtml4(s),然后得到结果。

© www.soinside.com 2019 - 2024. All rights reserved.