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!

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