rustHow can I compare two Rust strings with PartialEq?
You can compare two Rust strings with PartialEq by using the ==
operator. For example:
let string1 = "Hello";
let string2 = "World";
assert!(string1 != string2);
The output of this code will be assertion failed: string1 != string2
.
Code explanation
let string1 = "Hello";
- This declares a variablestring1
and assigns it the value"Hello"
.let string2 = "World";
- This declares a variablestring2
and assigns it the value"World"
.assert!(string1 != string2);
- This uses theassert!
macro to compare the two strings and check if they are not equal.
Helpful links
More of Rust
- How to get a capture group using Rust regex?
- How to use regex with bytes in Rust?
- How to match the end of a line in a Rust regex?
- Hashshet example in Rust
- How to create a new Rust HashMap with values?
- How do I use a variable from another file in Rust?
- How to get the length of a Rust HashMap?
- How to get an element from a HashSet in Rust?
- How to implement PartialEq for a Rust HashMap?
- How to convert the keys of a Rust HashMap to a vector?
See more codes...