From: David Alan Black Date: 2002-04-10T11:05:10+09:00 Subject: Re: Easy character comparisons Hello -- 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. (Is this in lieu of String#begins_with? :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav