How to get the second word of a string in Rust

1 Answer

0 votes
fn main() {
    let s = "c rust java c# python c++";
     
    let second_word = s.split_whitespace().nth(1).unwrap();
     
    println!("The second word is: {}", second_word);
}
 
 
   
/*
run:
 
The second word is: rust
 
*/

 



answered Oct 3, 2024 by avibootz
edited Oct 3, 2024 by avibootz
...