gpt4 book ai didi

c# - 你如何将 Html 转换为纯文本?

转载 作者:IT王子 更新时间:2023-10-29 03:38:31 25 4
gpt4 key购买 nike

我将 Html 片段存储在一个表中。 不是整个页面,没有标签等,只有基本格式。

我希望能够在给定页面上将该 Html 显示为纯文本,无格式(实际上只是前 30 - 50 个字符,但这很简单)。

如何将 Html 中的“文本”作为纯文本放入字符串中?

所以这段代码。

<b>Hello World.</b><br/><p><i>Is there anyone out there?</i><p>

变成:

Hello World 。有人吗?

最佳答案

麻省理工学院授权HtmlAgilityPackin one of its samples一种将 HTML 转换为纯文本的方法。

var plainText = HtmlUtilities.ConvertToPlainText(string html);

给它一个 HTML 字符串,比如

<b>hello, <i>world!</i></b>

你会得到一个纯文本结果,如:

hello world!

关于c# - 你如何将 Html 转换为纯文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/286813/

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