Android的转换ISO-8859-2到UTF-8 [英] Android convert ISO-8859-2 to UTF-8

查看:128
本文介绍了Android的转换ISO-8859-2到UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载远程文件的HTML源代码code到字符串变量。 Unfortunetely页是EN codeD通过ISO-8859-2,其中包含来自波兰的字母字符。我怎么能转换这个字符串为UTF-8,这样我就可以显示它的部件TextView的?

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?

感谢

推荐答案

您应该不需要转换字符串可言,如果你听从内容编码头由Web服务器发送。

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

现在,你可能忽略了头,而从服务器读取响应(一些的BufferedReader到的StringBuffer /生成器循环我假设),试试这个在下载code来代替:

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 它将自动使用指定的内容编码由服务器

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

这篇关于Android的转换ISO-8859-2到UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆