While trying out the escape sequence 'r', I again didn't get the results I expected.
I thought that there would be a blank line after the word return when keying this in...
2.1.3 :001 > puts "return\r"
return
=> nil
After finding out about \b, I decided to put a space after \r and the double quotation mark and this was what I got...
2.1.3 :002 > puts "return\r "
eturn
=> nil
This confused me even more until a few minutes later when I remembered that a carriage return was not what I thought it was. I remembered reading some documentation some time ago that \r returned the "focus", if you will, to the beginning of the line and that the line feed was a separate escape sequence altogether. That wasn't the terminology I read but that's how I remembered it.
2.1.3 :003 > puts "return\f"
return
=> nil
This is what I was expecting at first when using \r. I do know that the \f switch/option just moves the "focus" down a line in the same spot...kind of like using a typewriter and moving the page up one line. The type writer is going to type right where it's at unless it's moved to the beginning of that line. Necessary to know if using Ruby to look through strings or text files etc.
Starting at the beginning of the next line (just like you would with a typewriter), I'd need to use \r\f options like so...
2.1.3 :004 > puts "return\r\f"
return
=> nil
No comments:
Post a Comment