Backslashes in single quoted strings vs. double quoted strings

前端 未结 6 1887
挽巷
挽巷 2020-11-29 07:09

If I add a backslash+space to the start of double and single quoted strings, I get different results:

\"\\ text\"
\'\\ text\' 

In the outpu

6条回答
  •  时光取名叫无心
    2020-11-29 07:43

    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
    

提交回复
热议问题