Using Ruby 1.9.1, how can I access these string characters one at a time?

I do not know how else to explain, so I will give you a List of Greek words with English derivatives . Look at the table a, please, the first column. Note that there are type words ἄβαξ. Using Ruby 1.9.1, which has better coding support than Ruby 1.8, how can I iterate over each character forming this word? For example, I would like to get the letters in order, one at a time, for example:


β
α
ξ

I am not sure how to do this, since the method .sizereports a different string length than the ones we perceive. You can help?

+3
source share
2 answers

The following seems to work in 1.9

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

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 will find many good articles about Ruby 1.9 and character encoding.

+2
source

Source: https://habr.com/ru/post/1727686/


All Articles