In C#, what's the difference between \n and \r\n?

后端 未结 8 1258
礼貌的吻别
礼貌的吻别 2020-12-14 00:37

As per subject...

相关标签:
8条回答
  • 2020-12-14 00:44

    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

    0 讨论(0)
  • 2020-12-14 00:45

    "\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.

    0 讨论(0)
  • 2020-12-14 00:49

    \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 What is the difference between \r, \n and \r\n ?! for more information. Happy reading

    0 讨论(0)
  • 2020-12-14 00:54

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

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

    0 讨论(0)
  • 2020-12-14 00:54

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

    0 讨论(0)
  • 2020-12-14 00:57

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

    \r\n is used in windows

    \n is used in mac and linux

    0 讨论(0)
提交回复
热议问题