What is the difference between ASCII Chr(10) and Chr(13)
By Pete Freitag
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
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
Things such as HTTP headers or MIME mail headers are also delimited with a
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
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
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:
|Language||Line Feed / New Line||Carriage Return|
|Regular Expressions or RegEx|
|CFML / ColdFusion|
What is the difference between ASCII Chr(10) and Chr(13) was first published on May 17, 2019.
Tweet Follow @pfreitag