I have the following code:
string test = @"1
2
3";
This line:
Console.WriteLine(test.Replace("\n", "")); //3
prints "3", instead of "123", which is what I expected. Why does this method return only the last line of my string, and how can I otherwise remove all new-lines?
Console.WriteLine(test.Replace("\n", ""));
returns all numbers for me. When dealing with linebreaks you must be aware that newline may be\r\n
, it depends on platform. In this case you should use this:Refrer to Difference between “\n” and Environment.NewLine