- split
Split string into iterator
- split_whitespace method returning an iterator called SplitWhitespace.
examples/vectors/split-string-into-iterator/src/main.rs
fn main() { let text = String::from("mouse cat oliphant"); println!("{text}"); let parts = text.split(' '); //println!("{:?}", parts); for part in parts { println!("{}", part); } println!("-------"); let parts = text.split_whitespace(); //println!("{:?}", parts); for part in parts { println!("{}", part); } //println!("{}", parts[0]); // cannot index into a value of type `SplitWhitespace<'_>` }
mouse cat oliphant mouse cat oliphant ------- mouse cat oliphant