使用 cliente.DownloadString(url);给出奇怪的方形符号 c# .net 3.5

发布于 2024-12-04 03:48:31 字数 433 浏览 1 评论 0原文

我正在使用 webclient 从网站获取源 html 代码并将 html 放入文本框中,

但由于某种原因,在文本框中我得到了奇怪的符号

      using (WebClient cliente = new WebClient())
            {
                textbox.Text = cliente.DownloadString(url);
            }

,我正在使用 c# .net 3.5

http://imageshack.us/photo/my-images/691/weirdssymbols.jpg/

I'm using webclient 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/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久隐师 2024-12-11 03:48:31

这些是不可打印的换行符的表示。

尝试

 textBox.Multiline = true; 
 using (WebClient cliente = new WebClient())
 {
      textbox.Text = cliente.DownloadString(url);
 }

Those are representations of non-printable new line characters.

Try

 textBox.Multiline = true; 
 using (WebClient cliente = new WebClient())
 {
      textbox.Text = cliente.DownloadString(url);
 }
梦里人 2024-12-11 03:48:31

我认为这是与编码有关的问题。
你的字符串是utf-8编码的吗?

您需要将webclient编码设置为等于网页编码(如果您管理页面,将其设置为utf-8,是一个更好的解决方案)。

http://msdn .microsoft.com/en-us/library/system.net.webclient.encoding%28v=vs.80%29.aspx

然后,我认为你不会再得到坏方块了,但是我不知道文本框使用的编码,这可能是一个问题(我再次假设它们使用 utf-8,不知道它们是否可配置)。

编辑:

没有看到你的评论,是的,我认为这些方块是 \r\n 字符,它们(可能)是用与 uft-8 不同的编码写在页面上的(所以它不是这是你的错,但这是网页开发人员造成的问题)。

´ 无法转换,必须用 string.replace 为你想要的内容(´ 是 html 用来显示一些特殊字符的)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文