How to use escape characters in strings

前端 未结 2 1879
深忆病人
深忆病人 2021-01-03 10:40

I\'ve been working my way through the Ruby Koans and am confused by the \"escape clauses and single quoted strings\" examples.

One example shows that I can\'t reall

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 11:10

    This might be worth a read : http://en.wikibooks.org/wiki/Ruby_Programming/Strings

    ruby-1.9.3-p0 :002 > a = '\\\''
     => "\\'" 
    ruby-1.9.3-p0 :003 > a.size
     => 2 
    ruby-1.9.3-p0 :004 > puts a
    \'
    

    In single quotes there are only two escape characters : \\ and \'.

提交回复
热议问题