为什么WPF不能正确显示重音字符?

时间:2009-10-07 09:47:35

标签: wpf text character-encoding webclient downloadstring

我正在下载网页,然后将页面中的字符串加载到WPF UI中。 一个字符串有一个带重音的字符:“Ô。 在调试器中,字符串看起来很好,但是当添加到WPF ListBox时,它看起来像这样:Ã[] ine,其中[]是单个矩形符号。 当我从调试器UI复制文本并粘贴它时,Ã后面会出现一个空格。当WPF显示时,此“空格”显示为矩形符号。

有谁知道发生了什么事?

2 个答案:

答案 0 :(得分:0)

你的字符串可能包含一个“隐形”字符,它来自复制/粘贴或其他东西。尝试逐个字符地重写“éine”。

答案 1 :(得分:0)

修复是下载这样的网页:

WebClient c = new WebClient();
var bytes = c.DownloadData(url);
UTF8Encoding utf8 = new UTF8Encoding();
var s = utf8.GetString(bytes);

而不是像这样:

WebClient c = new WebClient();
var s = c.DownloadString(url);

WebClient.DownloadString无法正确下载页面并将其转换为字符串。