Sequentially iterate characters as character strings : each_char « String « Ruby






Sequentially iterate characters as character strings


s = "A\nB"                       # Three ASCII characters on two lines

# Works in Ruby 1.9, or in 1.8 with the jcode library:
s.each_char { |c| print c, " " } # Prints "A \n B "

 








Related examples in the same category

1.Use each_char with multibyte chars
2.Enumerate each character as a 1-character string