Search code examples
unicodeencodingruby-1.9

Using Ruby 1.9.1, how could I access this string's characters one at a time?


Let me start by giving you List of Greek words with English derivatives. Look at the a table, 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. What can I try next?


Solution

  • The following seems to work in 1.9

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