Newline character in C # line

I have html code in a C # line. If I look with the Visual Studio text visualizer, I see that it has a lot of new lines. However, after applying this code

string modifiedString = originalString.Replace(Environment.NewLine, "<br />"); 

and then I look with the help of Text Visualizer on modifiedString, I see that it no longer has new lines, except for three places. Are there other types of characters that resemble a new line, and am I missing?

+4
source share
2 answers

They can be just \r or \n . I just checked and the text renderer in VS 2010 displays both newlines and \r\n .

This line

 string test = "blah\r\nblah\rblah\nblah"; 

Shows how

 blah blah blah blah 

in the text visualizer.

So you can try

 string modifiedString = originalString .Replace(Environment.NewLine, "<br />") .Replace("\r", "<br />") .Replace("\n", "<br />"); 
+13
source

A great way to handle regular expressions.

 string modifiedString = Regex.Replace(originalString, @"(\r\n)|\n|\r", "<br/>"); 


This will replace any of the three legal newlines with the html tag.

+3
source

All Articles