Tramway11
Tramway11

Reputation: 419

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.

Upvotes: 15

Views: 25338

Answers (2)

wang willway
wang willway

Reputation: 505

You can add denpendency:

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

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

Upvotes: 1

Tarsem Singh
Tarsem Singh

Reputation: 14199

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()

Upvotes: 48

Related Questions