In Android, how to decode a UTF-8 encoded string?

I use the following data to decode a UTF-8 encoded string.

  • Actual line: 秦世俊: 用 "心" 工作 找到 属于 自己 的 成就感 【开讲 20160430】 T

  • UTF-8 encoded: |§ | 20160430ã "

. The output is the same as the input. What is the problem?

Method:

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

    } 
+4
source share
2 answers

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");
+3
source

use this

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

and if it does not work for you

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

Source: https://habr.com/ru/post/1655613/


All Articles