1

If I add this to the beginning of my script:

$KCODE = 'UTF8'
require 'jcode'

then I can walk over every char of a word containing unicode characters. Imagine a word containing umlauts or something, and I iterate over them like this:

word.each_char do |c|
  # do something with c
end

If c is a unicode character and I print it's size, it will be 2 ( composed of 2 characters ). How can I get c's code? Is there some formula I could use, or is there something in the std lib that can do this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Geo
  • 93,257
  • 117
  • 344
  • 520

1 Answers1

3

Should be:

c.unpack('U*').first
Mladen Jablanović
  • 43,461
  • 10
  • 90
  • 113