Search code examples
c#csv

Insert CRLF into a CSV file


I am iterating a datatable of C# and converting it into a CSV. I could use Environment.Newline to represent an end of one row and beginning of newline, ie CRLF (in CSV parlance).

But, is there any other way of representing a CRLF in a string ?


Solution

  • Environment.NewLine is platform independent.

    Nevertheless... on Windows it is \r\n. So your string could be:

    var content = "This is one Line 1\r\nand this is on Line 2";