【发布时间】:2010-11-05 16:48:00
【问题描述】:
我目前正在从内部数据库的字段中删除 html 标记。除了将
标签转换为纯文本换行符之外,一切都很顺利。
我想转换这个:
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.<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。
【问题讨论】:
-
我无法回答您的问题,但我必须赞扬您对您所问问题的解释和记录的能力。这么多 n00bs 会在第一段之后停止......
-
如果您在将行保存到数据库之前对其进行调试和中断,您是否会在字符串中看到 2 个新行标记?
-
谢谢。我在更改前后进行了调试和中断。当我在代码运行以删除
后查看调试器中的文本时,它看起来应该有两个段落。在该行之后,值被保存。然后我运行查询从数据库中提取值并将其粘贴到 Word 2003 但我只看到一个段落。 -
如果您实际上是从 Microsoft SQL 工具获取此信息,请尝试使用 Ctrl+T 进行文本输出(相对于网格)——这样应该可以正确显示换行符。