Reputation: 291
I'm using Mono for Android (C#) and WebClient DownloadString to get source code of a HTML website, that uses special characters (č,š,ž - charset=windows-1250). But when displaying the code, it shows � instead of the characters. Is there a way to show the correct characters? I'm using MonoDevelop.
Upvotes: 0
Views: 264
Reputation: 7088
When you use DownloadString
, .NET (and I suppose Mono, too) automatically assumes that downloaded data are encoded in UTF-8. In your case, that is not so, hence the � characters.
Instead of DownloadString
, use DownloadData
to download raw bytes and convert them to UTF-8:
byte[] win1250Bytes = webClient.DownloadData("http://whatever.com");
string utf8String = Encoding.GetEncoding("windows-1250").GetString(win1250Bytes);
Upvotes: 1