I want to replace all & characters into \& with String.gsub (or a other method). I've tried several combinations and read another question here, but nothing is gonna work.
"asdf & asdf".gsub("&", "\\\&") => "asdf & asdf"
Your linked question provides a solution - use the block form of gsub:
irb(main):009:0> puts "asdf & asdf".gsub("&"){'\&'}
asdf \& asdf
ruby-1.9.2-p180 :008 > puts "asdf & asdf".gsub(/&/, '\\\&')
asdf \& asdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With