views:

230

answers:

1

I want to unescape the following string:

'\u00020\u0002Standard\u00023\u0002Doe John\u000169\u0002\u0010\u0002Lorem\u0002\u0011\u0002Ipsum\u0002\u0014\u0002'

Javascripts unescape function works ok, however how can I unescape it in ruby?

Take in mind that unescape(previousString) is 0Standard3Doe John69LoremIpsum.

A: 

It seems to me that you're using Ruby 1.8, so you have poor encoding support.

In Ruby 1.8 the jcode library could but go here to find some 3rd party libraries that will help you. Ruby 1.9 has a better support for encoding, in fact It's one of the major changes of this release.

If you are in complete control over your application maybe you can encode your string without \u00020 kind of utf-8 entities, directly at Its source. This way you will avoid any regex parsing and CGI.unescapeHTML will work.

For reference and better understanding of unicode support in ruby JEG2 series will give you everything you need.

microspino
It doesn't work.
vise
I added some better directions since I think you're on Ruby 1.8.
microspino