15

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.

Raceimaztion
  • 9,494
  • 4
  • 26
  • 41
Tramway11
  • 419
  • 3
  • 9
  • 20

2 Answers2

48

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

Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
1

You can add denpendency:

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

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

wang willway
  • 415
  • 1
  • 3
  • 16