0

Ways To Compare Strings in Rust

Last Updated on

In Rust, we can use the eq(), eq_ignore_ascii_case() and ==.

Using eq() To Compare Strings

The function eq() is case-sensitive. In the codes below, we have a variable name that holds a static value which we compare with “karl” and “Karl”.

Output

For more information, please see Eq trait.

Using ==

This operator for strings is case-sensitive.

Output

Using eq_ignore_ascii_case()

Use eq_ignore_ascii_case() to compare strings without regards to their cases.

Output

For more information, please see notes.

Avatar

Karl San Gabriel

Professional Software Developer