To check if two strings are equal ignoring case in Ruby, you can use the casecmp
method to perform a case-insensitive comparison.
In this example,
str1
and str2
with different cases, such as "Hello"
and "hello"
.casecmp
method to compare the strings ignoring case.casecmp
method returns 0
if the strings are equal ignoring case, 1
if str1
is greater, and -1
if str2
is greater.0
to determine equality ignoring case.# Equality Check Ignoring Case in Ruby
str1 = "Hello"
str2 = "hello"
result = str1.casecmp(str2).zero?
puts "Strings are equal ignoring case: #{result}"
Strings are equal ignoring case: true
In this tutorial, we learned How to check if Two Strings are Equal ignoring case in Ruby language with well detailed examples.