开发者

How to get character's Unicode in Ruby 1.8.7?

To get character's Unicode in Ruby 1.9.2, I use ord:

"я".ord       # => 1103     (It's a Ru开发者_如何转开发ssian letter)

How could I get the Unicode in Ruby 1.8.7 ?


You could use my backports gem. Running with Ruby 1.8.7 (and option -KU to setup $KCODE for utf-8):

require "rubygems"
require "backports/1.8.7/string/ord"
"я".ord # => 1103


Well, I found this nice solution:

"я".unpack('U')[0]     # => 1103
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜