如何在字符串中将double-quotes
替换为"e;
?
这就是我的尝试:
1.9.3-p362 :009 > a = "\"That's it\", she said."
=> "\"That's it\", she said."
1.9.3-p362 :010 > a.tr('"', ""e;")
=> "&That's it&, she said."
正如您所看到的那样,"es;
而不是&
,我有任何想法?
答案 0 :(得分:4)
使用gsub
代替
a.gsub(/\"/, ""e;")
# without regex as noted by hirolau
a.gsub("\"", ""e;")
# => ""e;That's it"e;, she said."