Unescaping hex encoded characters in string?

If I have a string like “Don\x{2019}t Let Me Fall”

How do I unescape the hex encoded characters, in this cae convert the
string to “Don’t Let Me Fall”

On Thu, Sep 2, 2010 at 7:45 AM, sprite [email protected]
wrote:

If I have a string like “Don\x{2019}t Let Me Fall”

How do I unescape the hex encoded characters, in this cae convert the
string to “Don’t Let Me Fall”

In Ruby 1.9.* something along the lines of

str.gsub /\x{(\h{4})}/ do |code|
code.to_i(16).chr(str.encoding)

code.to_i(16).chr(Encoding::UTF_8)

end

Or use gsub! for inplace modification of the string. You might have
to twiddle with the encodings. Please see
http://blog.grayproductions.net/articles/miscellaneous_m17n_details

Kind regards

robert

On Sep 2, 3:26 am, Robert K. [email protected] wrote:

code.to_i(16).chr(Encoding::UTF_8)

remember.guy do |as, often| as.you_can - without endhttp://blog.rubybestpractices.com/
Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs