Reputation: 4054
So I have this method:
public static string ToProperText(this HtmlHelper helper, string text)
{
System.Diagnostics.Debug.WriteLine(text);
System.Diagnostics.Debug.WriteLine(text.Replace("\r\n", ""));
string lineSeparator = ((char)0x2028).ToString();
string paragraphSeparator = ((char)0x2029).ToString();
System.Diagnostics.Debug.WriteLine(text.Replace("\r\n", string.Empty).Replace("\n", string.Empty).Replace("\r", string.Empty).Replace(lineSeparator, string.Empty).Replace(paragraphSeparator, string.Empty));
System.Diagnostics.Debug.WriteLine(text.Replace("a", ""));
return null;
}
When called with some data from the database, this is the output:
<p>\r\n Vanaf nu worden de websiteberichten ook <u>automatisch</u> in de Nieuwssectie op het <strong>forum</strong> geplaatst.</p>\r\n
<p>\r\n Vanaf nu worden de websiteberichten ook <u>automatisch</u> in de Nieuwssectie op het <strong>forum</strong> geplaatst.</p>\r\n
<p>\r\n Vanaf nu worden de websiteberichten ook <u>automatisch</u> in de Nieuwssectie op het <strong>forum</strong> geplaatst.</p>\r\n
<p>\r\n Vnf nu worden de websiteberichten ook <u>utomtisch</u> in de Nieuwssectie op het <strong>forum</strong> gepltst.</p>\r\n
No matter what I do, the \r\n won't get removed from the string, although other replacements do work. Any idea what is going on here?
Thanks
Upvotes: 1
Views: 460
Reputation: 2043
Guessing here.. have you tried:
text.Replace("\\r\\n", "")?
"\r\n" would replace real line breaks, not the actual text '\r\n':
What character escape sequences are available?
Alternatively, duluca's option should work too.
Upvotes: 2
Reputation: 7333
Try
System.Diagnostics.Debug.WriteLine(text.Replace(@"\r\n", ""));
Look for the added @ symbol.
Upvotes: 1