1103 (It a Russian letter) Ho...">

How to get Unicode character in Ruby 1.8.7?

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

 "".ord # => 1103 (It a Russian letter) 

How can I get Unicode in Ruby 1.8.7 ?

+7
source share
2 answers

Ok, I found this nice solution:

 "".unpack('U')[0] # => 1103 
+7
source

You can use the gem backports . Starting with Ruby 1.8.7 (and the -KU option to install $KCODE for utf-8):

 require "rubygems" require "backports/1.8.7/string/ord" "".ord # => 1103 
+8
source

All Articles