To check if a string contains a specific character in Rust, you can use the 'contains' method of the string type.
In this example,
fn contains_character(s: &str, ch: char) -> bool {
s.contains(ch)
}
fn main() {
let s = "Hello World";
let ch = 'W';
let contains = contains_character(&s, ch);
println!("String contains character '{}': {}", ch, contains);
}
String contains character 'W': true
In this tutorial, we learned How to Check if String contains specific Character in Rust language with well detailed examples.