Android has two different ways to escape / encode HTML characters / entities in Strings:
Html.escapeHtml(String)
, added in API 16 (Android 4.1). The docs say:Returns an HTML escaped representation of the given plain text.
TextUtils.htmlEncode(String)
For this one, the docs say:Html-encode the string.
Reading the docs, they both seem to do pretty much the same thing, but, when testing them, I get some pretty mysterious (to me) output.
Eg. With the input: <p>This is a quote ". This is a euro symbol: €. <b>This is some bold text</b></p>
Html.escapeHtml
gives:<p>This is a quote ". This is a euro symbol: €. <b>This is some bold text</b></p>
Whereas
TextUtils.htmlEncode
gives:<p>This is a quote ". This is a euro symbol: €. <b>This is some bold text</b></p>
So it seems that the second escapes / encodes the quote ("), but the first doesn't, although the first encodes the Euro symbol, but the second doesn't. I'm confused.
So what's the difference between these two methods ? Which characters does each escape / encode ? What's the difference between encoding and escaping here ? When should I use one or the other (or should I, gasp, use them both together ?) ?