How to get the first and the second word of a string in Rust

1 Answer

0 votes
fn main() {
    let s = "c++ rust java c# python c";
     
    let mut words = s.split(' ');
     
    let first = words.next().unwrap();
    let second = words.next().unwrap();
     
    println!("{}", first);
    println!("{}", second);
}
 
 
   
/*
run:
 
c++
rust
 
*/

 



answered Oct 3, 2024 by avibootz
...