In Rust, you can use the ==
operator to check if two strings are equal.
In this example,
str1
and str2
with the same value "Hello"
.str1 == str2
, which will return true
if they are equal, and false
otherwise.fn main() {
let str1 = String::from("Hello");
let str2 = String::from("Hello");
let result = str1 == str2;
println!("Are strings equal? {:?}", result);
}
Are strings equal? true
In this tutorial, we learned How to check if Two Strings are Equal in Rust language with well detailed examples.