views:

201

answers:

2

I'm downloading a webpage, and then loading strings from the page into a WPF UI. One string has an accented character: "Áine". In the debugger, the string looks fine, but when added to a WPF ListBox, it appears like this: Á[]ine, where [] is a single rectangular symbol. When I copy the text from the debugger UI and paste it, a space appears after the Ã. This 'space' shows up as the rectangular symbol when displayed by WPF.

Does anyone know what's going on?

A: 

Your string might contain an "invisible" char that got there from a copy/paste or something. Try rewriting "Ãine" character by character.

Julien Lebosquain
The string is extracted from a webpage, so manually editing it isn't a solution.
mackenir
A: 

The fix was to download the webpage like this:

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

instead of like this:

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

WebClient.DownloadString was unable to properly download the page and convert it to a string.

mackenir