How to I get the Fixnum returned by the following:
"abc"[2]
Back into a character?
How to I get the Fixnum returned by the following:
"abc"[2]
Back into a character?
Be careful because Ruby 1.9 and later will return a single-character string for "abc"[2]
, which will not respond to the chr
method. You could do this instead:
"abc"[2,1]
Be sure to read up on the powerful and multifaceted String#[] method.