adding backslash to fix character encoding in ruby string
I'm sure this is very easy but I'm getting tied in a knot with all these backslashes. I have some data that I'm scraping (politely) from a website. Occasionally a sentence comes to me looking something like this: u00a362 000? you must be joking Which should of course be '£2 000? you must be joking'. A short test in irb deciphered it. ruby-1.9.2-p180 :001 > string = "u00a3" => "u00a3" ruby-1.9.2-p180 :002 > string = "\u00a3" => "£" Of course: add a backslash and it will be decoded. I created the following with the help of this question : puts str.gsub('u00', '\\u00') which resulted in \u00a3