How to split a string at the first occurrence of a separator in Rust

1 Answer

0 votes
fn main() {
    let str = "java rust, c c++, python, c#";
    
    let parts: Vec<&str> = str.splitn(2, ',').collect();  // Limit to 2 splits
    
    println!("{}", parts[0]);
    println!("{}", parts[1]);
}


 
 
/*
run:

java rust
 c c++, python, c#

*/

 



answered Aug 26, 2024 by avibootz

Related questions

...