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