Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find string escape sequences in the Ruby documentation?

Tags:

ruby

I can find details on Ruby's escape sequences in "Ruby Strings", and "Escape sequences". However, where in the official Ruby docs can I find details on string escape sequences?

This question is important for people who are just learning Ruby, as understanding how to simply navigate the documentation is an initial challenge.

like image 831
histelheim Avatar asked Nov 02 '13 16:11

histelheim


People also ask

How do you escape a string in Ruby?

When using strings in Ruby, we sometimes need to put the quote we used to define the string inside the string itself. When we do, we can escape the quote character with a backslash \ symbol.

What is string escape?

Escaping a string means to reduce ambiguity in quotes (and other characters) used in that string. For instance, when you're defining a string, you typically surround it in either double quotes or single quotes: "Hello World."


1 Answers

Please see the official documentation (or on ruby-doc.org) which has been updated with a full list of supported escape characters:

\a             bell, ASCII 07h (BEL)
\b             backspace, ASCII 08h (BS)
\t             horizontal tab, ASCII 09h (TAB)
\n             newline (line feed), ASCII 0Ah (LF)
\v             vertical tab, ASCII 0Bh (VT)
\f             form feed, ASCII 0Ch (FF)
\r             carriage return, ASCII 0Dh (CR)
\e             escape, ASCII 1Bh (ESC)
\s             space, ASCII 20h (SPC)
\\             backslash, \
\nnn           octal bit pattern, where nnn is 1-3 octal digits ([0-7])
\xnn           hexadecimal bit pattern, where nn is 1-2 hexadecimal digits ([0-9a-fA-F])
\unnnn         Unicode character, where nnnn is exactly 4 hexadecimal digits ([0-9a-fA-F])
\u{nnnn ...}   Unicode character(s), where each nnnn is 1-6 hexadecimal digits ([0-9a-fA-F])
\cx or \C-x    control character, where x is an ASCII printable character
\M-x           meta character, where x is an ASCII printable character
\M-\C-x        meta control character, where x is an ASCII printable character
\M-\cx         same as above
\c\M-x         same as above
\c? or \C-?    delete, ASCII 7Fh (DEL)

If you find anything to add or fix, we welcome feedback and contributions via pull-request on GitHub or via our issue tracker.

like image 168
Akinori MUSHA Avatar answered Sep 29 '22 08:09

Akinori MUSHA