我有一个通过剥离html来修改的datatable。在html条期间,如果遇到<br>、<p>或<li>,则用System.Environment.NewLine替换它们。我正在将html条带过程的每一个实例记录到一个文本文件中,并且格式在日志中看起来很好(所有的CRLF都被保留)。但是,当对datatable调用update方法并将数据发送到数据库时,CRLF字符将全部消失。
代码片段:
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);
}
}发布于 2012-05-25 02:45:21
SSMS将删除数据网格中的CRLF,但它们仍在数据库中。您可以通过按CTRL-T来证明这一点,它会将结果转换为文本,而不是网格。然后,您可以按CTRL-D键返回将结果显示在网格中。
您可以使用以下命令对其进行测试:
SELECT 'Not' + CHAR(10) + CHAR(13) + 'Together'首先在网格中显示结果:
(No Column name)
Not Together然后在文本结果中:
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
-------------
Not
Together
(1 row(s) affected)
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.https://stackoverflow.com/questions/10740905
复制相似问题