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 109 views
1 answer 83 views
1 answer 98 views
1 answer 98 views
1 answer 101 views
1 answer 77 views
2 answers 109 views
...