【发布时间】:2012-05-24 15:48:44
【问题描述】:
我有一个通过删除 html 来修改的数据表。在 html 条带期间,如果遇到 <br>、<p> 或 <li>,它们将替换为 System.Environment.NewLine。我正在将 html strip 进程的实例记录到文本文件中,并且格式在日志中看起来很好(所有 CRLF 都被保留)。但是,当在数据表上调用更新方法并将数据发送到数据库时,CRLF 字符都消失了。
代码sn-p:
public static class HtmlStripper
{
static Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);
static Regex _liRegex = new Regex("<li>", RegexOptions.Compiled);
static Regex _brRegex = new Regex("<(br)?(BR)?\\s?/?>\\s*", RegexOptions.Compiled);
static Regex _pRegex = new Regex("</?[phPH].*?>\\s*", RegexOptions.Compiled);
public static string StripTagsRegexCompiled(string source)
{
string noPorH = _pRegex.Replace(source, System.Environment.NewLine);
string noBr = _brRegex.Replace(noPorH, System.Environment.NewLine);
string noLi = _liRegex.Replace(noBr, System.Environment.NewLine + "t- ");
return _htmlRegex.Replace(noLi, string.Empty);
}
}
【问题讨论】:
-
一些代码片段将有助于回答您的问题。
-
您是否正在使用 Sql Server Management Studio 检查数据库中的数据?如果是这样,它会在显示时去掉换行符(但数据仍然正确)
-
我将数据从SSMS复制到Notepad++,CRLF字符都不见了。
-
@DanAndrews 那么你是说如果我在应用程序中使用这些数据会保留换行符吗?
-
所以是的,毕竟它是 SSMS。我从应用程序中查询了数据库并显示了数据,并且 CRLF 字符在那里。你每天都会学到一些东西。
标签: c# sql-server newline