如何删除html敏捷包中的空格和换行符 [英] how to remove white space and newline character in html agility pack

查看:71
本文介绍了如何删除html敏捷包中的空格和换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i正在使用html Agility包。



 HtmlWeb htmlWeb =  new  HtmlWeb(); 
的HTMLDocument的HTMLDocument = htmlWeb.Load(<跨度类= 代码串> <跨度类= 代码串 > http://en.wikipedia.org/wiki/Paintball );





out put like

< html xmlns = \http: //www.w3.org/1999/xhtml\\">\\\
\t<head></head>\\\
\t<body>\\\
\\\

Alle Auktionen

\ n \ n \\ n< / body> \ n< / html>



输出包含

不必要的空格和换行符



所以有没有办法摆脱没有空格和

换行符

解决方案

您可以在此产品的讨论页面中获得更快的回复:

HTML Agility Pack - 讨论 [ ^ ]。

<预lang =c#> private string GetDataFromURL( string URL)
{
HttpWebRequest myRequest_Snap =(HttpWebRequest)WebRequest.Create(URL);
myRequest_Snap.Method = GET;
WebResponse myResponse_Snap = myRequest_Snap.GetResponse();
的StreamReader sr_Snap = <跨度类= 代码关键字>新的StreamReader(myResponse_Snap.GetResponseStream(),System.Text.Encoding.UTF8);
string result = sr_Snap.ReadToEnd();
sr_Snap.Close();
myResponse_Snap.Close();

return result.Replace( )。替换( \ n );
}





打电话给



的字符串str = GetDataFromURL( http://en.wikipedia.org/wiki/Paintball); 


FAIS未分裂frrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr

Hi,

i am working with html Agility pack.

HtmlWeb htmlWeb = new HtmlWeb();
HtmlDocument htmlDocument = htmlWeb.Load("http://en.wikipedia.org/wiki/Paintball");



out put like
<html xmlns=\"http://www.w3.org/1999/xhtml\">\n\t<head></head>\n\t<body>\n\n

Alle Auktionen

\n\n\t</body>\n</html>

output contain

unnecessary whitespaces and newline characters


so is there any way to to get out put without whitespaces and

newline characters

解决方案

You may get a much quicker response in this product's discussion pages:
Html Agility Pack - Discussions[^].


private string GetDataFromURL(string URL)
        {
            HttpWebRequest myRequest_Snap = (HttpWebRequest)WebRequest.Create(URL);
            myRequest_Snap.Method = "GET";
            WebResponse myResponse_Snap = myRequest_Snap.GetResponse();
            StreamReader sr_Snap = new StreamReader(myResponse_Snap.GetResponseStream(), System.Text.Encoding.UTF8);
            string result = sr_Snap.ReadToEnd();
            sr_Snap.Close();
            myResponse_Snap.Close();

            return result.Replace(" ", "").Replace("\n", "");
        }



Call like

string str = GetDataFromURL("http://en.wikipedia.org/wiki/Paintball");


fais un split frrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr


这篇关于如何删除html敏捷包中的空格和换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆