0

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.

Bilow
  • 2,194
  • 1
  • 19
  • 34
  • You would be right if you are sending output to a teletype. But nobody uses a teletype anymore. \r\n is the correct sequence, you risk unexpected output when you reverse it. Like an extra linefeed in a program that tries to be resilient against conflicting Windows, Apple and Unix line-endings. YMMV, little point in having to answer that support phone call. – Hans Passant Aug 27 '18 at 11:18
  • I saw `\n\r` in my company's codebase... so I'm going to change it – Bilow Aug 28 '18 at 08:48
  • Who voted for close as opinion-based? The other question I'm talking about deserves this. Mine is objective. Please explain! – Bilow Aug 28 '18 at 08:49

1 Answers1

1

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).

melpomene
  • 84,125
  • 8
  • 85
  • 148