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 193 views
1 answer 155 views
1 answer 183 views
1 answer 176 views
1 answer 183 views
1 answer 170 views
2 answers 238 views
...