Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 删除字符串开头的特征线_C#_Html Agility Pack - Fatal编程技术网

C# 删除字符串开头的特征线

C# 删除字符串开头的特征线,c#,html-agility-pack,C#,Html Agility Pack,我正在使用HtmlAgilityPack为文本文件格式化html节点被替换为“\r\n”,因此它在文本文件中保持格式化。我希望删除第一个实际字符之前的所有特征线,但我的代码没有这样做。测试的最终输出应为:原始:你好检查预期:你好检查 html = "<br><br><br>Hello<br>Check"; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); var nodes =

我正在使用HtmlAgilityPack为文本文件格式化html
节点被替换为“\r\n”,因此它在文本文件中保持格式化。我希望删除第一个实际字符之前的所有特征线,但我的代码没有这样做。测试的最终输出应为:

原始:

你好
检查

预期:
你好
检查

html = "<br><br><br>Hello<br>Check";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);

var nodes = doc.DocumentNode.SelectNodes("//br");
if (nodes != null)
{
    foreach(var node in nodes)
    {
        node.ParentNode.ReplaceChild(doc.CreateTextNode("\r\n"), node);
    }
}

html = doc.Documentode.InnerText.TrimStart('r','n');
OutputLog.WriteLine("trimmed: " + html);
html=“


你好
检查”; HtmlDocument doc=新的HtmlDocument(); doc.LoadHtml(html); var nodes=doc.DocumentNode.SelectNodes(“//br”); 如果(节点!=null) { foreach(节点中的var节点) { node.ParentNode.ReplaceChild(doc.CreateTextNode(“\r\n”),节点); } } html=doc.Documentode.InnerText.TrimStart('r','n'); WriteLine(“修剪:+html”);
我希望删除第一个实际字符之前的所有特征线 但是我的代码没有做到这一点

使用正则表达式可以很容易地做到这一点

html = "<br><br><br>Hello<br>Check";
Regex.Replace(s,"^(?:<br>)+","\r\n") //Returns Hello<br>Check
html=“


你好
检查”; Regex.Replace(s,“^(?:
)+”,“\r\n”)//返回Hello
检查
然后,您可以根据需要处理html