I have a datatable that gets modified by having the html stripped out. During the html strip if a <br>, <p> or <li> is encountered they are replace with System.Environment.NewLine. I am logging ever instance of the html strip process to a text file and the formatting looks fine in the log (all CRLF are preserved). However when the update method is called on the datatable and the data gets sent to the database the CRLF characters are all gone.
Code snippet:
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);
}
}
SSMS removes CRLF in the data grid – however they are still there in the database. You can prove this by pressing
CTRL-Twhich turns your results to TEXT instead of in the GRID. You can then pressCTRL-Dto return to having your results in a GRID.You can test this with:
First by showing the result in the GRID:
Then in the TEXT result: