On 26.09.2006 15:02, Newbie wrote:
> This must be a common newbie question, but I can't find the answer.
> 
> Why does string#[] return an ASCII code, rather than a character?
> 
> "abc"[1,2] #-> "bc"
> "abc"[1..2] #-> "bc"
> "abc"[1] #-> 98

Because there is no character class in Ruby.  If you need a one 
character string you can do

irb(main):001:0> "abc"[2,1]
=> "c"
irb(main):002:0> "abc"[2].chr
=> "c"

I guess the former is more performant because the internal buffer can be 
shared.

Kind regards

	robert