From: Rich Kilmer Date: 2002-04-10T11:15:24+09:00 Subject: RE: Easy character comparisons Ah...yet another reason for: "string".begins_with? "s" => true (which does not work, but would be nice) -Rich PS. "string"[0..0] is about as good as it gets I'm afraid. > -----Original Message----- > From: Sean O'Dell [mailto:sean@celsoft.com] > Sent: Tuesday, April 09, 2002 9:37 PM > To: ruby-talk ML > Subject: Easy character comparisons > > 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. > > Sean