October 2006
Intermediate to advanced
888 pages
16h 55m
English
Because Ruby is not fully internationalized at the time of this writing, a character is essentially the same as a byte. To process these in sequence, use the each_byte iterator:
str = "ABC"
str.each_byte {|char| print char, " " }
# Produces output: 65 66 67In current versions of Ruby, you can break a string into an array of one-character strings by using scan with a simple wildcard regular expression matching a single character:
str = "ABC"
chars = str.scan(/./)
chars.each {|char| print char, " " }
# Produces output: A B CRead now
Unlock full access