Ruby中关於单引号和双引号的转义

单引号和%q只转义\(反斜杠)和‘(单引号),其他不转义

双引号和%Q转义所有。

a1 = 'hello \\world'
a2 = 'hello \nworld'
a3 = 'that\'s nice!'
b1 = "hello \\world"
b2 = "hello \nworld"
b3 = "that\'s nice!"
puts a1
puts a2
puts a3
puts b1
puts b2
puts b3

=>

hello \world
hello \nworld
that's nice!
hello \world
hello 
world
that's nice!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章