gpt4 book ai didi

c# - 删除 HTML 注释

转载 作者:太空狗 更新时间:2023-10-29 13:35:45 26 4
gpt4 key购买 nike

如何从 HTML 文件中删除评论?

它们可能只占一行,但我敢肯定我会遇到评论可能跨越多行的情况:

<!-- Single line comment. -->

<!-- Multi-
ple line comment.
Lots '""' ' " ` ~ |}{556 of !@#$%^&*()) lines
in
this
comme-
nt! -->

最佳答案

您可以使用 Html Agility Pack .NET 库。这是一篇解释如何在 SO 上使用它的文章:How to use HTML Agility pack

这是删除注释的 C# 代码:

    HtmlDocument doc = new HtmlDocument();
doc.Load("yourFile.htm");

// get all comment nodes using XPATH
foreach (HtmlNode comment in doc.DocumentNode.SelectNodes("//comment()"))
{
comment.ParentNode.RemoveChild(comment);
}
doc.Save(Console.Out); // displays doc w/o comments on console

关于c# - 删除 HTML 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5440392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com