Backslashes in single quoted strings vs. double quoted strings

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

    This is not a full answer (since the simple question has been answered already), but rather it is supplementary information.

    Which style of Ruby string quoting do you favour?

    Don't use double quotes if you have to escape them. And don't fall in "single vs double quotes" trap. Ruby has excellent support for arbitrary delimiters for string literals:

    http://rors.org/2008/10/26/dont-escape-in-strings

    I took that advice and have never looked back!

提交回复
热议问题