要在 Ruby 1.9.2 中获取字符的 Unicode,我使用ord
:
"я".ord # => 1103 (It's a Russian letter)
我怎样才能在Ruby 1.8.7中获得 Unicode ?
你可以用我的backports
宝石。使用 Ruby 1.8.7 运行(以及-KU
设置$KCODE
utf-8 的选项):
require "rubygems"
require "backports/1.8.7/string/ord"
"я".ord # => 1103
Well, I found this nice solution:
"я".unpack('U')[0] # => 1103