To check if two strings are equal ignoring case in Swift, you can convert both strings to lowercase or uppercase and then compare them using the ==
operator.
In this example,
str1
and str2
with different cases, such as "Hello"
and "hello"
.lowercased()
or uppercased()
methods.==
operator.true
if the strings are equal ignoring case, and false
otherwise.// Equality Check Ignoring Case in Swift
let str1 = "Hello"
let str2 = "hello"
let result = str1.lowercased() == str2.lowercased()
print("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 Swift language with well detailed examples.