Android convert ISO-8859-2 to UTF-8

我们两清 提交于 2019-12-23 05:11:24

问题


I'm downloading HTML source code of remote page into String 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


回答1:


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.



来源:https://stackoverflow.com/questions/7368233/android-convert-iso-8859-2-to-utf-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!