I'm REALLY new at rust, and it is throwing me some curves.
What I want to do is just grab the first word off of a string, spliting at a space.
let chunks:Vec = vec!(address_string.split(" ").collect());
println!("{}",chunks[0]);
It prints out the whole original string, with the spaces removed. I assume the "collect()" statement is to blame for this, but the split function won't work without it. It would be just about as useful to have a vector with all the words in the string, but, I don't know how to get there either.
My first attempt was this, and got the same results:
let chunks:String = address_string.split(" ").collect();
println!("{}",chunks);
If you want the words separated, then try the following:
let chunks: Vec<String> = address_string.split(" ").collect();
for i in chunks {
println("{}", i);
}
This first splits them, and stores them into a Vec<String> and then iterates through them and prints them.
If you collect them into a string then you'll end up with the chunks glued together into a single string, resulting in the same string, just without the spaces.
To get a vector, collect is the right method. But if, as you say, you just step through and do something with each element, you possibly don't need a vector. Just use a for loop over the iterator (what is returned by split).