How to split a string into a vector in Rust

1 Answer

0 votes
fn main() {
    let str = "rust c java c++ python";
    
    let vec: Vec<&str> = str.split(' ').collect();
    
    println!("{:?}", vec);
}


  
/*
run:

["rust", "c", "java", "c++", "python"]

*/

 



answered Sep 20, 2024 by avibootz

Related questions

2 answers 126 views
1 answer 101 views
1 answer 117 views
2 answers 135 views
...