Edit: So, as is often the case,
@mikeyww and I had the same thoughts - he's just a faster typist! Between the two of them, hopefully your question is answered. My original post is below, before I saw that he had beat me to the punch.
So - a little bit of history is in order here.
CR (Carriage Return) and
LF (Line Feed) are holdovers from the days before video terminals, when
Teleprinters (also known as Teletypes, like "Kleenex" is used generically for tissues) were the way that humans interfaced with computers. (Yes, I remember those days!) A teleprinter was basically a typewriter with a continuous roll of paper attached. You may have seen them in old movies where news flashes were coming over the "wire".
When the printer portion was active by receiving input either from the human via the keyboard or from the computer via an RS-232 cable, each character received would be printed on the roll of paper and the print head ("carriage" - a holdover from the manual typewriter) would physically advance forward ready to print the next character. In order for the print head to "return" to the left margin, a "carriage return" (
CR, ASCII 13) would be sent from the computer or by pressing the "Return" key on the keyboard. This would physically move (return) the print head to the left margin, BUT, it would NOT advance the paper one line - those were separate operations. If you tried to print multiple lines of text with nothing but
CRs at the end, they would all print over top of one another.
Now meet the
LF (Line Feed - ASCII 10) character. Any time the teleprinter received one of those, the paper would advance, but the print head would not move. Printing "T
LFe
LFs
LFt" would look like this on the paper:
Usually, the manual keyboard was set up in such a way that pressing "Return" would send both a
CR and a
LF code to the printer, although either could also be sent individually.
Fast forward a little to the advent of the personal computer. Microsoft decided to maintain the standard of sending both a
CR and a
LF at the end of a line of text within a text file. When Unix (and Linux) were created, it was decided that all that was needed in a text file was the
LF character between lines and called it the "New Line"
Things get a little muddy now with software languages that have to accommodate these different methods. AHK has the escaped characters
`r ("Return") and
`n ("New Line") How do they work? The following screen shots are from Notepad++ with "display all characters" turned on.
If we write the following code with just
`r ("Return") between each word:
Code: Select all
FileAppend, This`ris`ra`rtest`r, test.txt
We get the following whether we precede the file name with an asterisk or not:
- image.png (3.02 KiB) Viewed 299 times
If we use the following code with just the
`n ("New Line") between words and no asterisk:
Code: Select all
FileAppend, This`nis`na`ntest`n, test.txt
We get the Microsoft standard (both
CR and
LF:
- image.png (2.83 KiB) Viewed 299 times
If, however, we preface the file name with an asterisk, i.e.
Code: Select all
FileAppend, This`nis`na`ntest`n, *test.txt
We get the Unix/Linux standard format of just the
LF ("New Line") character between words:
- image.png (2.59 KiB) Viewed 299 times
All of this really only applies to writing text files with
FileAppend. When using any AHK command that searches and/or replaces characters, the
`r always only represents the "Carriage Return" character and the
`n always represents the "Line Feed" character. This is why you must sometimes search or split a string using both in succession. Note that it is customary to place the
CR (`r) before the
LF (`n) when searching for the pair.
So, have I totally confused you now? Hope this sheds some light on the subject.
Russ