I have some html code in a C# string. If I look with the Text Visualizer of Visual Studio I can see it has numerous newlines in it. However, after i apply this code
string modifiedString = originalString.Replace(Environment.NewLine, "<br />");
and then I look with the Text Visualizer at modifiedString I can see it doesn't have anymore newlines except for 3 places. Are there any other character types than resemble newline and I am missing?
In most C compilers, including ours, the newline escape sequence '\n' yields an ASCII line feed character. The C escape sequence for a carriage return is '\r'.
LF (character : \n, Unicode : U+000A, ASCII : 10, hex : 0x0a): This is simply the '\n' character which we all know from our early programming days. This character is commonly known as the 'Line Feed' or 'Newline Character'.
in Unix and all Unix-like systems, \n is the code for end-of-line, \r means nothing special.
They might be just a \r
or a \n
. I just checked and the text visualizer in VS 2010 displays both as newlines as well as \r\n
.
This string
string test = "blah\r\nblah\rblah\nblah";
Shows up as
blah
blah
blah
blah
in the text visualizer.
So you could try
string modifiedString = originalString
.Replace(Environment.NewLine, "<br />")
.Replace("\r", "<br />")
.Replace("\n", "<br />");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With