irb(main):166:0> new_str = str.gsub(/\"/,'\\"').gsub(/\n/,'\\n')
=> "--- \\nFrench: \\\"3. Combien de r\\xC3\\xA9gions y a-t-il au
Cameroon?\\\"\\nEnglish: 3. How many regions are there in
Cameroon?\\n"
2. Run it through an eval:
irb(main):167:0> eval "new_str = \"#{new_str}\""
=> "--- \nFrench: \"3. Combien de régions y a-t-il au
Cameroon?\"\nEnglish: 3. How many regions are there in Cameroon?\n"
Where is this text coming from? Because that string looks like YAML, complete with the opening “—”. \xC3\xA9 is the UTF-8 encoding of codepoint U+00E9, “small letter e with acute”, something you’d expect in French text.
If you do YAML.load(str) in 1.9 or higher, this is what appears:
irb: YAML.load(str)
===> {“French”=>“3. Combien de régions y a-t-il au Cameroon?”, “English”=>“3. How many regions are there in Cameroon?”}
When I copied the OP’s string as written, and fed it to YAML.load, it flubbed the translation, reversing thebyte order. As far as I can tell, I have UTF-8 set everywhere.
So I’m not sure why it works for you but not for me…