Jaume Jaume - 2 months ago 14
Java Question

android UTF8 encoding from received string

I am receiving a string that is not properly encoded like "mystring%201, where must be "mystring 1". How could I replace all characters that could be interpreted as UTF8? I read a lot of posts but not a full solution. Please note that string is already encoded wrong and I am not asking about how to encode char sequence. I asked same issue for iOS few days ago and was solved using stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding. Thank you.

ios UTF8 encoding from nsstring


You should be able to use the URLDecoder.decode() function, like this:

String s = URLDecoder.decode(myString, "UTF-8");

More info here: URLEncoder encode / URLDecoder decode in java (Android)