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
精彩评论