Reputation: 11
Can anyone advise what is the ideal approach to recognize line break in a database column's data?
Using \r\n
or chr(10)
? What is the difference actually?
Does C# code need to do any special handling to split the lines or it will be recognized automatically?
Upvotes: 1
Views: 612
Reputation: 9577
\r
is char(13)
known as the "Carriage Return" character.\n
is char(10)
known as the "Line Feed" character. \r\n
is char(13) + char(10)
i.e. case 1 & 2 are concatenated.Different operating systems use different combinations when reading or writing new lines in text data, the most common are:
In C# you can handle all 3 cases by splitting the lines like this:
string[] lines = dbText.Split(new string[] { "\r\n", "\n", "\r" },
StringSplitOptions.None);
Other characters and combinations are used by other operating systems and this subject even has it's own Wikipedia page with way more detail than you'll probably ever need!
Upvotes: 3