Skip to content Skip to sidebar Skip to footer

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

Solution 1:

You can use the URLDecoder.decode() function, like this:

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

Solution 2:

Looks like your string is partially URL-encoded, so... how about this:

try {
 System.out.println(URLDecoder.decode("mystring%201", "UTF-8"));
} catch(UnsupportedEncodingException e) {
 e.printStackTrace();
}

Solution 3:

I am receiving a string that is not properly encoded like "mystring%201

Well this string is already encoded, you have to decode:

StringsDecoded= URLDecoder.decode("mystring%201", "UTF-8");

so now sDecoded must have the value of "mystring 1".

The "Encoding" of String:

StringsEncoded= URLEncoder.encode("mystring 1", "UTF-8");

sEncoded must have the value of "mystring%201"

Post a Comment for "Android Utf8 Encoding From Received String"