Pete Freitag Pete Freitag

What is the difference between ASCII Chr(10) and Chr(13)

Updated: May 26, 2020

typewriters have a carriage return

Writing this because I can never remember which ascii code is \n and which is \r. Usually I end up googling my ASCII Cheatsheet for the answer. So here it is fully explained in case you are curious:

What is Chr(10)

The ASCII character code 10 is sometimes written as \n and it is sometimes called a New Line or NL. ASCII character 10 is also called a Line Feed or LF.

On a UNIX based operating system such as Linux or Mac it is all you typically use to delineate a line in a file.

What is Chr(13)

The ASCII character code 13 is called a Carriage Return or CR. On windows based computers files are typically delimited with a Carriage Return Line Feed or CRLF. So that is a Chr(13) followed by a Chr(10) that compose a proper CRLF.

Things such as HTTP headers or MIME mail headers are also delimited with a CRLF.

If you have ever opened a file with notepad on windows and found that it appears that everything is on one line, but then open it in another editor to find that the lines appear, the reason for that is that the file is delimited with only LF Chr(10) and not CRLF. Notepad is not smart enough to know the difference and plops everything on one line. Most text editors on windows besides notepad have no problem with working on files that are only delimited with \n or Chr(10).

This all dates back to the typewriter

The term Carriage Return actually dates back to when typewriters were commonly used. When you hit enter on a typewriter it will advance the paper to the next line (line feed!), however unless you return the carriage (that lever that you move to the left) you would keep typing, here's an example:

I will hit enter now
                    but I forgot to return the carriage

So what should I use as a file line delimiter?

I tend to use only Chr(10) because it takes less space. Unless you have a use case where people will be opening the files you create with notepad, this should work fine.

Also if your file needs to be interfaced with a typewriter, I would make sure you are using a Carriage Return ;-)

Is it Char(10) or Chr(10)?

The name of the function to return an ascii character from an integer character code is not consistent across programming languages. So it depends what language you are using, here is a handy table with some popular languages:

LanguageLine Feed / New LineCarriage Return
Regular Expressions or RegEx\n\r
CFML / ColdFusionChr(10)Chr(13)

Like this? Follow me ↯

What is the difference between ASCII Chr(10) and Chr(13) was first published on May 17, 2019.


When I was a kid we had this manual typewriter in the basement and there was no power or enter key. You just had a big lever and a little lever. The little lever could be set to 1 or 2 for single or double spacing. If you just pushed the big lever it a little, it would advance 1/2 the little lever setting. A little more it would advance the whole little lever setting, and you had to hold it while moving the carriage to the left to do the Carriage Return. If your hand slipped, it would make you do the line feed(s) again to get it back to the beginning of the line. It's amazing to think about how technology has change over the years.
by Steve on 04/09/2020 at 12:25:27 PM UTC

Post a Comment