Reminder - \r\n or \n\r?

前端 未结 10 1746
轻奢々
轻奢々 2020-11-30 16:37

I just can\'t remember those. So, what is the right way to properly terminate old fashioned ASCII lines?

相关标签:
10条回答
  • 2020-11-30 17:25

    \r\n

    Odd to say I remember it because it is the opposite of the typewriter I used.
    Well if it was normal I had no need to remember it... :-)

    *Image from Wikipedia

    In the typewriter when you finish to digit the line you use the carriage return lever, that before makes roll the drum, the newline, and after allow you to manually operate the carriage return.

    You can listen from this record from freesound.org the sound of the paper feeding in the beginning, and at around -1:03 seconds from the end, after the bell warning for the end of the line sound of the drum that rolls and after the one of the carriage return.

    0 讨论(0)
  • 2020-11-30 17:25

    if you are using C#, why not using Environment.NewLine ? (i assume you use some file writer objects... just pass it the Environment.NewLine and it will handle the right terminators.

    0 讨论(0)
  • 2020-11-30 17:29

    From Wikipedia (you can read which is correct for your OS at that article):

    Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, '\r\n', 0x0D0A).

    0 讨论(0)
  • 2020-11-30 17:36

    New line depends on your OS:

    DOS & Windows: \r\n 0D0A (hex), 13,10 (decimal)
    Unix & Mac OS X: \n, 0A, 10
    Macintosh (OS 9): \r, 0D, 13
    

    More details here: https://ccrma.stanford.edu/~craig/utility/flip/

    When in doubt, use any freeware hex viewer/editor to see how a file encodes its new line.

    For me, I use following guide to help me remember: 0D0A = \r\n = CR,LF = carriage return, line feed

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