From: Bill Kelly Date: 2002-01-22T07:06:17+09:00 Subject: Re: converting chars to numeric From: "Mark Probert" > 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 :-). a = s[0] - ?0 # at least eliminates the hardcoded 48 or a = s[0].chr.to_i or even a = s[0..0].to_i # though to me this one "looks" weird Regards, Bill