From: Boris Glawe Date: 2005-05-19T20:30:14+09:00 Subject: Re: accessing each character of a string : THANKS Assaph Mehr wrote: > Boris Glawe wrote: > >>Hi, >> >>my problem is obviously very basic, but how to I acces for example > > the third > >>character of the string "hello" ?? >> >>The [] method does not behave as expected, the each method returns > > the whole > >>string, the methods of Enumerable mixin don't help me... >> >>This can't be that hard to solve!? >> >>thanks Boris > > > Just convert the Fixnum into a character: > > irb(main):005:0> s = 'hello' > => "hello" > irb(main):006:0> s[2] > => 108 > irb(main):007:0> s[2].chr > => "l" > thanks that's as smooth as I expected it from ruby :-) Solutions like string[2..2], as they are shown in the documentation, are not very nice! greets Boris