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

2019-01-22 11:59发布

As per subject...

9条回答
家丑人穷心不美
2楼-- · 2019-01-22 12:43

Use Environment.NewLine and don't care.

查看更多
家丑人穷心不美
3楼-- · 2019-01-22 12:46

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

\r\n is used in windows

\n is used in mac and linux

查看更多
Emotional °昔
4楼-- · 2019-01-22 12:54

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

查看更多
登录 后发表回答