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"

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

Kind regards

robert

···

On Thu, Sep 2, 2010 at 7:45 AM, sprite <aake.gregertsen@gmail.com> 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"

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

Thanks

···

On Sep 2, 3:26 am, Robert Klemme <shortcut...@googlemail.com> wrote:

On Thu, Sep 2, 2010 at 7:45 AM, sprite <aake.gregert...@gmail.com> 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 seehttp://blog.grayproductions.net/articles/miscellaneous_m17n_details

Kind regards

robert

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