std-method

str::split_whitespace

Separate text at Unicode whitespace, skipping empty runs. This is useful for simple tokenization, not language-aware word segmentation. Expected stdout (not executed): ["سلام", "دنیا"] Common mistake: Expecting punctuation or zero-width non-joiners to be treated as whitespace.

Formal Syntax & Structure

rust syntaxrust
fn split_whitespace(&self) -> SplitWhitespace<'_>

Working Example

Example Snippetrust
fn main() {    let words: Vec<_> = "  سلام دنیا  ".split_whitespace().collect();    println!("{words:?}");}
Rust Reference