How can I convert a string of codepoints to the string it represents?
I have a string (in 开发者_如何转开发Ruby) like this:
626c6168
(that is 'blah' without the quotes)
How do I convert it to 'blah'? Note that these are variable lengths, and also they aren't always letters and numbers. (They're being stored in a database, not being printed.)
Array#pack
['626c6168'].pack('H*')
# => "blah"
Using hex
to convert each character:
"626c6168".scan(/../).map{ |c| c.hex.chr }.join
This gives blah
.
精彩评论