views:

101

answers:

8

As per subject...

+3  A: 

"\n" is just a line feed (Unicode U+000A). This is typically the Unix line separator.

"\r\n" is a carriage return (Unicode U+000D) followed by a line feed (Unicode U+000A). This is typically the Windows line separator.

Jon Skeet
+1  A: 

Basically comes down to Windows standard: \r\n and Unix based systems using: \n

http://en.wikipedia.org/wiki/Newline

James Hulse
+12  A: 

The Difference

There are a few characters which can indicate a new line. The usual ones are these two:

* '\n' or '0x0A' (10 in decimal) -> This character is called "Line Feed" (LF).
* '\r' or '0x0D' (13 in decimal) -> This one is called "Carriage return" (CR).

Different Operating Systems handle newlines in a different way. Here is a short list of the most common ones:

* DOS and Windows

They expect a newline to be the combination of two characters, namely '\r\n' (or 13 followed by 10).

* Unix (and hence Linux as well)

Unix uses a single '\n' to indicate a new line.

* Mac

Macs use a single '\r'.

Taken from Here

Dave
Book marking for future reference - thanks
Preet Sangha
+1  A: 

It's about how operating system recognize line ends.

  • windows user \r\n
  • mac user \r
  • linux uses \n

Morale: if you are developing for windows, stick to \r\n. Or even better, use C# string functions to deal with strings which already consider line endings (WriteLine, and such).

Palantir
+2  A: 

Use Environment.NewLine and don't care.

Grozz
Unless he is reading files generated by other software.
Adrian Grigore
+1  A: 

\n is the line break used by Unix(-like) systems, \r\n is used by windows. This has nothing to do with C#.

Adrian Grigore
+2  A: 

\n is Unix, \r is Mac, \r\n is Windows.

Sometimes it's giving trouble especially when running code cross platform. You can bypass this by using Environment.NewLine.

Please refer to http://social.msdn.microsoft.com/forums/en-US/csharplanguage/thread/47af2197-26b4-4b9e-90e8-bfa9d5cd05b4 for more information. Happy reading

Peter van Kekem
+1  A: 

They are just \r\n and \n are variants.

\r\n is used in windows

\n is used in mac and linux

Vinothbabu