Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created March 3, 2010 23:00
Show Gist options
  • Save thinkerbot/321152 to your computer and use it in GitHub Desktop.
Save thinkerbot/321152 to your computer and use it in GitHub Desktop.
examples of escaped strings in ruby
# String escapes:
#
# \a Bell/alert (0x07)
# \b Backspace (0x08)
# \e Escape (0x1b)
# \f Formfeed (0x0c)
# \n Newline (0x0a)
# \r Return (0x0d)
# \s Space (0x20)
# \t Tab (0x09)
# \v Vertical tab (0x0b)
# \nnn Octal nnn
# \xnn Hex nn
# \cx Control-x
# \C-x Control-x
# \M-x Meta-x
# \M-\C-x Meta-control-x
# \x x
# see http://www.csgnetwork.com/asciiset.html
# halfway down the page is some mappings of
# various control characters to octal
puts "abc" # => "abc"
puts "\141\142\143" # => "abc" in octal
puts "\cx\C-x".inspect # => "\030\030"
puts "\030\030".inspect # => "\030\030"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment