开发者

Android convert ISO-8859-2 to UTF-8

开发者 https://www.devze.com 2023-04-04 01:48 出处:网络
I\'m downloading HTML source code of remote page into St开发者_运维百科ring variable. Unfortunetely the page is encoded via iso-8859-2 and contains characters from polish alphabet. How can I convert t

I'm downloading HTML source code of remote page into St开发者_运维百科ring variable. Unfortunetely the page is encoded via iso-8859-2 and contains characters from polish alphabet. How can I convert this string to utf-8, so I can display it's parts in TextView?

Thanks


You shouldn't need to "convert" the string at all, if you obey the Content-Encoding header sent by the web server.

Right now, you probably ignore that header while reading the response from the server (some BufferedReader-to-StringBuffer/Builder loop I assume), try this in your download code instead:

HttpResponse response = ....
String text = EntityUtils.toString(response.getEntity());

EntityUtils will automagically use the content encoding specified by the server.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号