From: Alexander Schofield Date: 2002-01-22T07:08:23+09:00 Subject: Re: converting chars to numeric You can use a range index like: s[0..0] (extracts only the first char as string) Also useful for extracting substrings like s[0..2], extracts '456' Mark Probert wrote: > > Hi. > > I am new to ruby and coming from a Perl environment. > > Can someone tell me if there is a nice way to do the following: > > s = "4567" > a = s[0] # --> I want the value '4' not '54', the > ASCII value of 4 > b = s[1] # --> 5 > a + b # --> 9 > > I can do this by saying > > a = s[0] - 48 > > though this seems a might ugly for ruby :-). > > TIA, > > -mark.