views:

67

answers:

2

I don't know how else to explain, so I'll give you List of greek words with english derivatives. Look at the a table, please, first column. Notice there are words like ἄβαξ. Using Ruby 1.9.1, which has better encoding support than Ruby 1.8, how could I iterate over each character forming that word? For example, I'd like to get the letters in order, one at a time, like:

ἄ
β
α
ξ

I'm not really sure how to go about that, as the .size method reports a different length of the string than the ones we perceive. Can you help?

+2  A: 

Example:

#!/usr/bin/env ruby19

str = "ἄβαξ"
puts "#{str} - encoding: #{str.encoding.name} / size: #{str.size}"
str.each_char do |c|
  puts c
end

Using some Google-fu, you'll find a lot of good articles on Ruby 1.9 and character encoding.

Lytol
+1  A: 

The following seems to work in 1.9

testStr="ἄβαξ"
testStr.each_char { |k|
        puts k
}
Jamie