Usman Rana
Usman Rana

Reputation: 2142

In Android, How to decode UTF-8 encoded String?

I 'm using following data to decode the UTF-8 encoded String.

. Output is same as input. What is the issue?

Method:

public String decodeString(String encodedString) {
            return new String(encodedString.getBytes(), "UTF-8");

    } 

Upvotes: 5

Views: 16310

Answers (2)

Rahul Khurana
Rahul Khurana

Reputation: 8835

use this

String s2 = new String(bytes, "UTF-8"); // Charset with which bytes were encoded 

and if it doesn't work for you

String decoded = new String(encoded.getBytes("ISO-8859-1"));

Upvotes: 3

Preetika Kaur
Preetika Kaur

Reputation: 2031

Just Use String result = URLDecoder.decode(string, "UTF-8");

Or use this

byte[] data = Base64.decode(base64, Base64.DEFAULT);
String text = new String(data, "UTF-8");

Upvotes: 5

Related Questions