To get character's Unicode in Ruby 1.9.2, I use ord
:
"я".ord # => 1103 (It's a Russian 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With