I don't know the difference between `r and `n

Get help with using AutoHotkey and its commands and hotkeys
kwfine
Posts: 16
Joined: 26 Nov 2015, 06:46

I don't know the difference between `r and `n

03 Jun 2018, 05:59

Hi all,

I wrote a simple code to help me copy things from Google news.

The built-in code I used most was this:

Code: Select all

MouseClickDrag
But sometimes MouseClickDrag copied some unwanted line break,
to avoid this, I had added these two lines in my AHK codes:

Code: Select all

;I copied these two lines from Google search

Clipboard := StrReplace(Clipboard, "`r", "")
Clipboard := StrReplace(Clipboard, "`n", "")
I don't know the difference between `r and `n, so I used both `r and `n at the time.
Could you tell me their difference please?

Thank you!

Kitty
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: I don't know the difference between `r and `n

03 Jun 2018, 06:18

\n and \r are different characters in ASCII, used for representing new line in text. Linux's and general standard is just n (line feed) character for new line, but some/most Microsoft Windows' programs (at least these old ones) use \r\n instead (where r - carriage return). They are presented this way to be "printable" and readable, but to differ them for the normal characters - escape key is used (\ in most languages, ` in AHK by default).
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
garry
Posts: 2286
Joined: 22 Dec 2013, 12:50

Re: I don't know the difference between `r and `n

03 Jun 2018, 06:22

`r is ascii 13 ( CR carriage return )
`n is ascii 10 ( LF line feed )
I use both , `r`n in textfile as end of line (EOL)
in msgbox is `n ok : msgbox,Line1`nLine2

other ascii codes :
EOF 26 End of File
FF 12 Form Feed , when used matrix printer moved to next sheet

TAB `t 09 Tab
BS `b 08 Backspace

transform,s,chr,32 ; SPACE , variable %s% is same as %a_space%
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: I don't know the difference between `r and `n

04 Jun 2018, 01:20

\n is a line feed, the standard end of line in linux
\r\n is a hard line feed or carriage return linefeed, the standard end of line in windows, hated by contrarians ;)
\n in windows is a soft line feed often used to mark where you hit ctrl+enter
both demark the end of a line but also in many case define if the next line is part of the same paragraph, a feature less commonly used now.

Lost is the reason of the use.... in typewriters, teletypes and dot matrix printers the carriage return instructed the machine to go to the start of the line... and linefeed instructed the machine to move to the next line. a \n without a \r the machine would simply scroll to the next line

Code: Select all

so you\n
      could tell the printer\n
                            to move to the next line and write text there\r\n
to save on the speed on the printing
you could also send\n\b\b\b\b\b
               backspaces\n\b\b\b\b\b\b\b\b\b\b
               to align text with the line above if the number of backspace would save on head movement
It did not matter if the machine encountered \r\n or \n\r the result would be the same. \r\n or \n\r, resulted in same head position

long story short. replacing all \r\n with \n is something you will often need to do when dealing with text. and writing \r\n for newline is something you should always do if your code is running under windows.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: I don't know the difference between `r and `n

04 Jun 2018, 02:19

- The symbol (arrow) on the Enter key is a bit misleading, it suggests down first (line feed) and left (carriage return), but Windows uses CR then LF.
- Can anyone find a good video demonstrating the physical meanings on a typewriter/other hardware? I couldn't find one.
- Notepad finally added proper support for CR and LF in Windows 10.
Introducing extended line endings support in Notepad – Windows Command Line Tools For Developers
https://blogs.msdn.microsoft.com/comman ... n-notepad/
- If it doesn't work in Notepad (i.e. the enters are there but don't display), you can try WordPad. You can also try copying in Notepad and pasting somewhere else, this can reveal the hidden enters.
- A further thing to know about is word wrap in Notepad, it creates CRCRLFs. Create at least one long line, set word wrap to on, and save the file, then try ControlGetText on the Edit control.
Why does Windows Vista's Notepad randomly move the cursor after saving a file? - Super User
https://superuser.com/questions/57190/w ... ing-a-file

Code: Select all

q:: ;reveal hidden enters
ControlGetText, vText, Edit1, A
vText := StrReplace(vText, "`r", "_R")
vText := StrReplace(vText, "`n", "N_")
MsgBox, % vText
return
- Another thing is that in older versions of Windows (e.g. XP but not 7), if you do Ctrl+Left and Ctrl+Right, that will stop halfway through the 'enter' (line break), between the CR and the LF. Thankfully this was later changed (I believe it's to do with the properties of Edit controls rather than anything Notepad-specific.) I ended up with what I call lone enter characters, after having used Ctrl+Shift+Left/Right and Del to delete words. (I had assigned Ctrl+Backspace/Ctrl+Del hotkeys which I still use.)
EM_SETWORDBREAKPROC message (Windows)
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: I don't know the difference between `r and `n

04 Jun 2018, 03:55

>Can anyone find a good video demonstrating the physical meanings on a typewriter/other hardware? I couldn't find one.
I did not realise people were so out of touch.
The carriage is what the printer head sits on. it "carries" the print head left to right... or it carries the paper roller right to left for typewriter whose head does not move. backspace moves it in reverse

Roller carriage
https://www.youtube.com/watch?v=9TWMtYFSHuw

Print Head sitting on a carriage
https://www.youtube.com/watch?v=vNUEUth7qjc

a line feed is when you would roll the roller by one notch, to the next line, some printer had half notches to allow subscript and super script. this could be done turning the roler with the knobs on both sides or nudging the arm lightly on the left...

The arm on the old carriage serves as line feed and return. if you push on it more you push the carriage to the start, returning it to its original position. it does the linefeed first then your arm does the carriage return :)

And that there is why linefeed by itself is wrongly associated with going at the start of the next line. without the carriage returning to the start, a line feed is just a tick of the roller.


as for the carret placing itself between \r\n I do believe that may have been buggy software :)

the wordwrap proc... it's actually EM_FMTLINES which is interesting, I never heard of it until recently.
Last edited by icuurd12b42 on 04 Jun 2018, 04:12, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: I don't know the difference between `r and `n

04 Jun 2018, 04:06

- Thanks icuurd12b42.
- I've seen a tonne of places describe in words, carriage return and line feed, but not a simple really explicit video.
- This one was quite good, but didn't explicitly mention CR and LF from an IT perspective.
How to Use a Typewriter - YouTube
https://www.youtube.com/watch?v=FkUXn5bOwzk
- You should get the caret between CR and LF on Windows XP on any multiline Edit control, by doing Ctrl+Left/Ctrl+Right. Possibly on Windows Vista, I'm not sure.
- Re. technology, I heard of a child/teen asking: why do they say 'hang up' the phone, and a video of a small kid trying to swipe a book. Technology moves fast. Bring back the slide rule.
- Thanks for the videos, I like the Ferrero Rocher that they use to change the font/typeface.
- I wrote a script so that you can set word wrap to on without losing the caret's position, by getting the current column and CR/LF count, setting word wrap to on, then setting the caret position.
- I'm not entirely sure of the EM_FMTLINES details, I was working on a Notepad clone, when I get back to it, I might need to look at it then.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: I don't know the difference between `r and `n

04 Jun 2018, 04:28

Caret \r\n: Not sure. I been on windows since the 90's (and typewriters before that :P). ctrl+left/right have always been next word, prev word, but I may not remember things 100% being do old and going senile... and I did have my one experience with this caret between \r \n lately with coding my edit box to code box hack, placing the caret wrongly between the \r and \n... which really break things.

Watching the video...
"Turn the carriage knob like so"... it's the roller you %^&%$....
"Every time I do a Come back over". You mean every time you do a carriage return!!!
"Line space selector" You mean linefeed selector!
Hehe. well he got all bases covered anyway.

You can see where all them word processors reflect how you set margins and tabs :)
Helgef
Posts: 4410
Joined: 17 Jul 2016, 01:02
Contact:

Re: I don't know the difference between `r and `n

04 Jun 2018, 04:34

I recommend this instructional video.

Cheers.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: I don't know the difference between `r and `n

04 Jun 2018, 13:15

- Great post Helgef, one of the best on these forums, nicely done.
- Once I had to fill in a survey that had a section with a character limit, and each time you pressed enter, the number remaining went down by 2 characters.
- Of course it's like handwriting also, in a left-to-right writing system, when you reach the end of a line: hand moves left (CR), hand moves down (LF).
- Another technology classic: 8-inch, 5¼-inch, and 3½-inch floppy disks.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: benbory, Bing [Bot], Google [Bot], jimhoyle, TXShooter, vsub and 291 guests