Search code examples
windowscarriage-returnlinefeed

Line feed - Is \n\r valid?


In an Windows environment:

\r (Carriage Return) moves the cursor to the beginning of the line without advancing to the next line.

\n (Line Feed) moves the cursor down to the next line without returning to the beginning of the line.

According to these definitions, \r\n and \n\r could be used interchangeably, am I right?

It should not matter whether you go down then left or left then down.

This question is similar, but it tells what everyone is used to, instead of explaining why.


Solution

  • Depends on the context.

    If you're controlling an actual typewriter: Yes, they're the same.

    If you're talking about file formats or network protocols: No, you have to use the right sequence of bytes (regardless of the reason those bytes were chosen originally).