0

I have one ruby script which parses one CSV and generates some XML files. In this process, I am stuck at changing

it's free

to

it\'s free

Seems to be a trivial task, but I couldn't complete it.

Tried below

gsub("'","\'")
Akhil
  • 6,667
  • 4
  • 31
  • 61
  • `CSV.generate(headers: true) { |csv| csv << [r1c1, r1c2]; csv << [r2c1, r2c2] }`, you can create csv content by above `r1c1` is nothing but string content of first ro first column – ray Dec 10 '18 at 05:23
  • @mu-is-too-short solution mention here https://stackoverflow.com/a/7074726/1677824 is not working for me. It prints extra \ in result ```source.gsub("'","\\\\'") => "It\\'s Free"``` – Akhil Dec 10 '18 at 07:35
  • @Akhil That's because you're looking at the result in `irb` which uses `#inspect` to display the value of the last expression. Look at `puts source.gsub("'","\\\\'").inspect` and `puts source.gsub("'","\\\\'")` and you'll see the difference. – mu is too short Dec 10 '18 at 17:52
  • Thanks @mu-is-too-short it worked !! – Akhil Dec 11 '18 at 09:41

0 Answers0