如何在字符串中将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;,而不是&,你知道吗?
发布于 2013-11-08 12:24:44
使用gsub代替
a.gsub(/\"/, ""e;")
# without regex as noted by hirolau
a.gsub("\"", ""e;")
# => ""e;That's it"e;, she said."https://stackoverflow.com/questions/19859027
复制相似问题