Search code examples
javaandroidutf-8non-ascii-charactersutf8-decode

Transform encoded UTF-8 characters to special accented characters in android


In Java, I have a string obtained from an API, which looks like:

Hola, ésto es una frase con acentos.

And I want to have:

Hola, ésto es una frase con acentos.

Not only for this example, I need it for all UTF-8 encoded characters.

I've been looking for this for an hour but I haven't found a solution.


Solution

  • This isn't encoding, it's an HTML numeric character reference.

    The easiest way to deal with it is add the Apache Commons Lang library to your project, and call StringEscapeUtils.unescapeHtml4