我有例如r = "\t"
和a = "thisisabigbad\wolf"
如何防止ruby自动转义我的字符串并同时计算\
?
a.count r #=> this should return 2 instead of 0
我希望a.count
并接收2
答案 0 :(得分:0)
您可以使用单引号:
[17] pry(main)> r = '\t'
=> "\\t"
[18] pry(main)> r.size
=> 2
[20] pry(main)> a = 'thisisabigbad\wolf'
=> "thisisabigbad\\wolf"
[21] pry(main)> a.size
=> 18