With a string like "1 foo\n2 bar\n3 foobar", how do I split it into:
[["1", "foo"], ["2", "bar"] ["3", "foobar"]]
This will work.
fn main() {
let string: Vec<Vec<&str>> = "1 foo\n2 bar\n3 foobar".split('\n')
.map(|x: &str| x.split(' ').collect())
.collect();
println!("{:?}", string);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With