开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜