Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

rust
communitycreator

What is string.eq_ignore_ascii_case() in Rust programming?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

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.

Syntax

string1.eq_ignore_ascii_case(&string2)
The syntax for checking if two strings are case-insensitive

Parameters

string1: This is the string we want to compare with another string2.

Return value

The value returned is a boolean value. If the strings match, then a true is returned. Otherwise, a false is returned.

Example

fn main() {
// create some strings
let 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 case
println!("{}", str1.eq_ignore_ascii_case(&str2)); // true
println!("{}", str3.eq_ignore_ascii_case(&str4)); // true
println!("{}", str5.eq_ignore_ascii_case(&str6)); // true
println!("{}", str7.eq_ignore_ascii_case(&str8)); // false
}
Using the string.eq_ignore_ascii_case() method in Rust

Explanation

  • Lines 3–8We declare some strings.
  • Lines 11–14: We check if the strings are ASCII and that they match with their cases ignored. We print the result to the console.

RELATED TAGS

rust
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring