Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android string encoding and html entities converting

There is a String in Android Java. How do I change it to another given encoding and replace HTML-entities such as & with &?

This is so that international symbols can be displayed correctly.

like image 753
Tramway11 Avatar asked Jul 14 '13 20:07

Tramway11


2 Answers

to decode Html String you can use Html.fromHtml()

like

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

if you want reverse

than you can use TextUtils.htmlEncode()

like image 159
Tarsem Singh Avatar answered Nov 02 '22 00:11

Tarsem Singh


You can add denpendency:

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

And use StringEscapeUtils.unescapeHtml4(s), then get the result.

like image 1
wang willway Avatar answered Nov 02 '22 00:11

wang willway