views:

49

answers:

1

I have to read some text files with the following content:

\u201CThe Pedlar Lady of Gushing Cross\u201D

In ruby 1.9 terminal, when I create a string with this content:

ruby-1.9.1-p378 > "\u2714 \u2714 my great string \u2714 \u2714"
 => "✔ ✔ my great string ✔ ✔" 

In ruby 1.8, I don't get the unicode codes converted to their characters:

ree-1.8.7-2010.01 > "\u2714 \u2714 my great string \u2714 \u2714"
 => "u2714 u2714 my great string u2714 u2714" 

Is there any easy way to return the right string chars in Ruby 1.8?

A: 

The simplest approach might be to use a JSON parser, as JSON happens to use this very format:

irb(main):014:0> JSON '["\u2714 \u2714 my great string \u2714 \u2714"]'
=> ["\342\234\224 \342\234\224 my great string \342\234\224 \342\234\224"]
Martin v. Löwis