How to perform a case-insensitive search in Rust

1 Answer

0 votes
fn contains_ignore_case(haystack: &str, needle: &str) -> bool {
    haystack.to_lowercase().contains(&needle.to_lowercase())
}

fn main() {
    let str = "The FOX Profession is Rust Programmer";
    let to_find = "fox";

    let contains = contains_ignore_case(str, to_find);

    println!("{}", contains);
}

 
      
/*
run:
   
true
     
*/

 



answered Feb 24, 2025 by avibootz

Related questions

1 answer 201 views
1 answer 159 views
1 answer 187 views
1 answer 181 views
1 answer 187 views
1 answer 177 views
2 answers 243 views
...