Reputation: 21618
How can I replace double-quotes
to "e;
in a string?
This is what I have tried:
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."
As you see instead of "es;
I only get &
, any idea?
Upvotes: 1
Views: 4126
Reputation: 8331
use gsub
instead
a.gsub(/\"/, ""e;")
# without regex as noted by hirolau
a.gsub("\"", ""e;")
# => ""e;That's it"e;, she said."
Upvotes: 4