gpt4 book ai didi

c# - 将
解析为纯文本新段落

转载 作者:太空狗 更新时间:2023-10-29 14:13:59 33 4
gpt4 key购买 nike

我目前正在从内部数据库的字段中删除 html 标签。除了将
标记转换为纯文本换行符外,一切都进行得很顺利。

我想转换这个:

The victory halted Spain&rsquo;s 35-game unbeaten streak, handing the Spanish their first defeat since November 2006. The Americans now advance to the final Sunday to face the winner of Thursday&rsquo;s semifinal between South Africa and Brazil, the five-time World Cup winner. Brazil defeated the Americans, 3-0, in their earlier meeting in this tournament.<br>
<br>
In the final, though, the United States will be without midfielder Michael Bradley, who received a red card for a harsh tackle in the 87th minute, the third such ejection for the Americans in this tournament. It was the only careless blemish on an otherwise nearly perfect evening.

在此:

The victory halted Spain’s 35-game unbeaten streak, handing the Spanish their first defeat since November 2006. The Americans now advance to the final Sunday to face the winner of Thursday’s semifinal between South Africa and Brazil, the five-time World Cup winner. Brazil defeated the Americans, 3-0, in their earlier meeting in this tournament.

In the final, though, the United States will be without midfielder Michael Bradley, who received a red card for a harsh tackle in the 87th minute, the third such ejection for the Americans in this tournament. It was the only careless blemish on an otherwise nearly perfect evening.

我正在使用以下代码行将
更改为换行符:

value = value.Replace("<br>", Environment.NewLine).Trim();

运行该代码后,这是保存在我的数据库中的内容:

The victory halted Spain's 35-game unbeaten streak, handing the Spanish their first defeat since November 2006. The Americans now advance to the final Sunday to face the winner of Thursday's semifinal between South Africa and Brazil, the five-time World Cup winner. Brazil defeated the Americans, 3-0, in their earlier meeting in this tournament.    In the final, though, the United States will be without midfielder Michael Bradley, who received a red card for a harsh tackle in the 87th minute, the third such ejection for the Americans in this tournament. It was the only careless blemish on an otherwise nearly perfect evening.

如果我将已解析的文本保存到我的数据库并将其粘贴到记事本或 Word 中,我只会得到一段而不是两段。

这是处理这个问题的正确方法吗?我使用的数据库是 SQL Server 2005。

最佳答案

您使用Environment.Newline 的方法是正确的。我认为问题在于如何在 SQL Server 中直接返回某些查询,假设您直接从 SQL Server Management Studio(或类似工具)中复制/粘贴。

我大约 99% 肯定,如果您使用 SqlConnection 提取数据,然后将其输出到 winform、文本文件等...那么您将得到您正在寻找的换行符。

抱歉,我不记得为什么当您直接从 SQL Server 的结果网格中复制/粘贴时会发生这种情况。

关于c# - 将 <br> 解析为纯文本新段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1041426/

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