Use each_char with multibyte chars : each_char « String « Ruby






Use each_char with multibyte chars



s = "¥1000"
s.each_char {|x| print "#{x} " }         # Prints "¥ 1 0 0 0". Ruby 1.9
0.upto(s.size-1) {|i| print "#{s[i]} "}  # Inefficient with multibyte chars

 








Related examples in the same category

1.Sequentially iterate characters as character strings
2.Enumerate each character as a 1-character string