We can check if two strings are the case-sensitive match using the eq_ignore_ascii_case()
method. The method also lets us check if they are ASCII strings.
string1.eq_ignore_ascii_case(&string2)
string1
: This is the string we want to compare with another string2
.
The value returned is a boolean value. If the strings match, then a true
is returned. Otherwise, a false
is returned.
fn main() {// create some stringslet str1 = "Welcome";let str2 = "WELCOME";let str3 = "tO";let str4 = "tO";let str5 = "EDPREsso";let str6 = "edpresso";let str7 = "Rust";let str8 = "Solidity";// check if they match without minding their caseprintln!("{}", str1.eq_ignore_ascii_case(&str2)); // trueprintln!("{}", str3.eq_ignore_ascii_case(&str4)); // trueprintln!("{}", str5.eq_ignore_ascii_case(&str6)); // trueprintln!("{}", str7.eq_ignore_ascii_case(&str8)); // false}