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 106 views
1 answer 76 views
1 answer 92 views
1 answer 93 views
1 answer 95 views
1 answer 71 views
2 answers 103 views
...