Enumerate each character as a 1-character string : each_char « String « Ruby






Enumerate each character as a 1-character string


s = "A\nB"                       # Three ASCII characters on two lines
# This does not work for multibyte strings in 1.8
# It works (inefficiently) for multibyte strings in 1.9:

0.upto(s.length-1) {|n| print s[n,1], " "}

 








Related examples in the same category

1.Use each_char with multibyte chars
2.Sequentially iterate characters as character strings