Backslashes in single quoted strings vs. double quoted strings

前端 未结 6 1889
挽巷
挽巷 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:48

    Is this because the '\ ' is interpreted as a special character in the double quote string but in the single quoted string the characters are preserved as is?

    Yes. Single-quoted strings are treated as literals; double-quoted strings are interpolated. This is the same in other Ruby-like languages, and hasn't changed in 1.9.

提交回复
热议问题