How to check if a string starts with a specified substring in Rust

1 Answer

0 votes
fn main() {
    let string = "Rust Programming Language";
    let substring = "Rust";

    if string.starts_with(substring) {
        println!("yes");
    } else {
        println!("no");
    }
}

  
     
/*
run:
  
yes
    
*/

 



answered Feb 10, 2025 by avibootz
...