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
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
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.