- ends_with
Rust - string ends with
examples/strings/ends-with/src/main.rs
fn main() { let names = [String::from("name.txt"), String::from("other")]; for name in names { print!("name: '{name}'"); if name.ends_with(".txt") { print!(" ends with .txt"); } println!(); } }
name: 'name.txt' ends with .txt name: 'other'