views:

251

answers:

1

Hi

I need to check for

"Apple" = "Apple" TRUE
"Apple" = "APPLE" TRUE
"Apple" =  "Apple1" FALSE

in ruby

I need a string comparison but for the check to not be case sensitive.

thks

+8  A: 

You're looking for casecmp. It returns 0 if two strings are equal, case-insensitively.

str1.casecmp(str2) == 0

"Apple".casecmp("APPLE") == 0
#=> true

Alternatively, you can convert both strings to lower case (str.downcase) and compare for equality.

molf
This worked fantastically :D thank you very much
Steven