From: Euan Mee Date: 2002-04-10T14:41:49+09:00 Subject: Re: Easy character comparisons On 10 Apr 2002, David wrote (more or less): > On Wed, 10 Apr 2002, Sean O'Dell wrote: > > Today I spent a little time debugging something I "didn't expect." I > > evaluated (using if) string[index] against a single character in a string > > and for awhile, I couldn't figure out why it wasn't working. Then I > > realized that string[index] returns a number, not a string containing a > > single character. Example: > > "string"[0] == "s" => false > > I ended up having to change the expression to something like this: > > "string"[0..0] == "s" => true > > Is there a more elegant way of doing this sort of comparison? My fudged way > > seems awkward. > > > You could do: > > "string"[0].chr == "s" > > Not shorter, but maybe nicer-looking. For me (a relative Nuby) this seems by far the most legible of the alternatives posted. Cheers, Euan