gpt4 book ai didi

c# - 去掉 HTML 标签?

转载 作者:行者123 更新时间:2023-12-03 03:10:59 31 4
gpt4 key购买 nike

如何删除此文本

<html>

<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>
<test@test.com>
</body>
</html>

看起来像

My First Heading
My first paragraph.
<test@test.com>

使用函数

public static string StripHTML(this string htmlText)
{
var reg = new Regex("<(.|\n)*?>", RegexOptions.IgnoreCase);
return reg.Replace(htmlText, "");
}

我明白

我的第一个标题我的第一段。

最佳答案

使用Html Agility Pack对于此类操作。它比任何正则表达式都要快,并且支持 LINQ。

关于c# - 去掉 HTML 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7790309/

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