Re: \n?? \r??

From: James Curran (JamesCurran_at_mvps.org)
Date: 09/17/04


Date: Fri, 17 Sep 2004 12:20:13 -0400


"Sarah" <Sarah@discussions.microsoft.com> wrote in message
news:C4BEF541-4382-4659-AFE0-F0DC49A9A7C1@microsoft.com...

> what's the difference between \n and \r

    To understand the characters, you need to know a little history.
When the original ASCII standard was defined, computers used teletypes for
interacting with users --- Video monitors were rare to nonexistent. Moving
to a new line was a two step process: you had to move the carriage (the
thing stamping letters on the paper) back to the left margin, and you had to
advance the paper up one line. When the control codes were defined, it was
decided that these actions would be given separate codes, for more flexible
control over printing. For one thing, this allowed over- printing --
returning the carriage without advance to paper, so the next line is printed
on top of the last. The most common use for this was to obscure a password
the user had to enter, so it couldn't be read by someone pulling an old
listing out of the garbage. So, char 10 (0x0A) is defined as a "Line Feed"
(LF), and char 13 (0x0D) is defined as "carriage return" (CR)

    As CRT terminals started to be used, separate codes was less important,
but hard disk space was at a premium, so OS designer started to use the
convention of using just one of the characters as an "End of Line" code.
Most people used CR; UNIX, in their iconoclastic way, chose LF instead.
When the C language was defined --- by Unix users --- they made LF the "next
line" character ('\n'), and throw in CR ('\r') as a sop to everyone else.
(Those symbols were carried over to C++ & C#)

    Then in 1982, IBM announced it's PC, and, at the same time, finally
decided to embrace ASCII (they had been using the very bizarre EBCDIC
before), --- and really embraced it and actually required both CR LF
characters as and end-of-line, as it said in the official ignored standard.
Most of the systems using just CR eventually converted to CR LF, or just
faded away. Unix, on the other hand, continued using just LF.

    So, now (c1985) we have a programming language (C), producing files with
just a LF, and an operating system (MS-DOS) requiring CR LF. So, the
authors of C Run-time library created the concept of "text mode" files,
where, when reading files it would convert CR LF into LF, and when writing
files it would convert LF to CR LF. (Similarly, this has been carried over
of C++'s iostreams & to the .Net CLR)

-- 
Truth,
James Curran
Home: www.noveltheory.com       Work: www.njtheater.com
Blog: www.honestillusion.com  Day Job: www.partsearch.com
                                                (note new day job!)


Relevant Pages

  • Re: POS Printer
    ... printer These special codes are non-printable ... characters ... I see no reason to be concerned with it at all. ... I know that a POS printer has an internal buffer so just because we send ...
    (microsoft.public.vc.mfc)
  • Re: =?ISO-8859-1?Q?Soup=E7on_of_cedilles_and_aper=E7us?=
    ... Above that are the so-called "extended ASCII codes", ... neither of the non-7-bit-ASCII characters display. ... Unfortunately Mike does not have MIME enabled in his software, ... they are superior to the modern newsreaders. ...
    (alt.usage.english)
  • Re: How to get the plain text (without "||||||||||") from word ducment includes table?
    ... I have tried the Paragrph-By-Paragraph resolvent, ... I guess those additional marks might be defined ... cause in that those codes always be out ... >> number of characters retrieved from Range.Text doesnt equal to it that ...
    (microsoft.public.office.developer.com.add_ins)
  • Re:
    ... In practice, other differences can be more important, such as special treatment of U+00A0 as table cell content by web browsers. ... Technically, when appearing in an element, the difference of the codes of the characters is important, since it's the code that is sent as part of the form data. ...
    (comp.infosystems.www.authoring.html)
  • Re: 2 PCs not visible in net view or network browsing - Why?
    ... The 16 characters names (counting the ending HEX codes ... ALL NetBIOS names are really 16 characters. ... > into DNS name? ...
    (microsoft.public.win2000.networking)