Difference between \n and \r?

前端 未结 10 754
予麋鹿
予麋鹿 2020-11-21 11:17

What’s the difference between \\n (newline) and \\r (carriage return)?

In particular, are there any practical differences between

10条回答
  •  灰色年华
    2020-11-21 11:52

    Since nobody else mentioned it specifically (are they too young to know/remember?) - I suspect the use of \r\n originated for typewriters and similar devices.

    When you wanted a new line while using a multi-line-capable typewriter, there were two physical actions it had to perform: slide the carriage back to the beginning (left, in US) of the page, and feed the paper up one notch.

    Back in the days of line printers the only way to do bold text, for example, was to do a carriage return WITHOUT a newline and print the same characters over the old ones, thus adding more ink, thus making it appear darker (bolded). When the mechanical "newline" function failed in a typewriter, this was the annoying result: you could type over the previous line of text if you weren't paying attention.

提交回复
热议问题