Kerry Buckley

What’s the simplest thing that could possibly go wrong?



As far as I can tell, this is the correct way to do case-insensitive string comparison in Ruby:

if string1.casecmp(string2) == 0
  # strings match, ignoring case

That’s so ugly, it almost looks like Java. Actually, it’s worse than Java, which has String#equalsIgnoreCase.

Written by Kerry

November 8th, 2007 at 1:31 pm

Posted in Java,Ruby

4 Responses to 'String#casecmp'

Subscribe to comments with RSS or TrackBack to 'String#casecmp'.

  1. We need to do that for Mojo too as .NET creates the hex digest in upper case =/


    8 Nov 07 at 2:19 pm

  2. Yeah yeah, already done :-) – that’s where I found it.


    8 Nov 07 at 3:02 pm

  3. This looks better to me:

    string1.downcase == string2.downcase

    Brian Marick

    8 Nov 07 at 3:18 pm

  4. You could use regular expressions:

    string1 =~ /^string2$/i


    12 Nov 07 at 4:00 pm

Leave a Reply

You must be logged in to post a comment.