std-method

str::split_inclusive

Split into chunks retaining the matched delimiter at the end of each corresponding chunk. Expected stdout (not executed): a; b; c Common mistake: Assuming the final chunk always ends with a delimiter.

Formal Syntax & Structure

rust syntaxrust
text.split_inclusive(pattern)

Working Example

Example Snippetrust
fn main() {    for line in "a;b;c".split_inclusive(';') { println!("{line}"); }}
Rust Reference