using cliente.DownloadString(url); give weird square symbols c# .net 3.5
I'm using we开发者_高级运维bclient to get the source html code from websites and put the html in a textbox
but for some reason in the textbox I'm gettig weird symbol
using (WebClient cliente = new WebClient())
{
textbox.Text = cliente.DownloadString(url);
}
I'm using c# .net 3.5
http://imageshack.us/photo/my-images/691/weirdssymbols.jpg/
Those are representations of non-printable new line characters.
Try
textBox.Multiline = true;
using (WebClient cliente = new WebClient())
{
textbox.Text = cliente.DownloadString(url);
}
I think that it's a problem connected to encoding. Is your string utf-8 encoded?
You need to set the webclient encoding equals to web page enconding (if you manage the page, set it to utf-8, is a better solution).
http://msdn.microsoft.com/en-us/library/system.net.webclient.encoding%28v=vs.80%29.aspx
Then, I think you wouldn't get bad squares anymore, however I don't know encoding used by textboxes, this could be a problem (I again suppose they use utf-8, don't know if they are configurable).
EDIT:
Didn't see your comment, yes definitely I think those squares are \r\n characters, which (maybe) are written on the page with an encoding different from uft-8 (so it's not your fault but it's a problem that the webpage's developer created).
´ can't be converted, you must replace with string.replace with what you want (´ is used by html to show some special characters)
精彩评论