Backslashes in single quoted strings vs. double quoted strings

Double-quoted strings support the full range of escape sequences, as shown below:

  • \a Bell/alert (0x07)
  • \b Backspace (0x08)
  • \e Escape (0x1b)
  • \f Formford (0x0c)
  • \n Newline (0x0a)
  • \r Return (0x0d)
  • \s Space (0x20)
  • \t Tab (0x09)
  • \v Vertical tab (0x0b)

For single-quoted strings, two consecutive backslashes are replaced by a single backslash, and a backslash followed by a single quote becomes a single quote:

'escape using "\\"' -> escape using "\"
'That\'s right'     -> That's right

Leave a Comment