I have a script that sometimes prints a newline as \n and sometimes uses \r\n. What is the difference between the two, and is one preferable over the other?
Asked
Active
Viewed 4.7k times
14
David542
- 101,766
- 154
- 423
- 727
-
possible duplicate of [\r\n , \r , \n what is the difference between them?](http://stackoverflow.com/questions/15433188/r-n-r-n-what-is-the-difference-between-them) – Games Brainiac Jan 30 '15 at 02:46
2 Answers
17
"\n" is the class Unix/linux style for new line. "\r\n" is the default Windows style for line separator. "\r" is classic Mac style for line separator. I think "\n" is better, because this also looks good on windows, but some "\r\n" may not looks so good in some editor under linux, such as eclipse or notepad++. If you are handling some protocols, the "\r\n" is usually required.
Cui Heng
- 1,217
- 8
- 10