Esta página ainda não foi traduzida, por isso é exibida em inglês. Ajude a traduzir

split

Splits an iterable of single-character strings on a separator character.

Iterable<String> split(String sep, Iterable<String> iterable) FxAsyncIterable<String> splitAsync(String sep, FxAsyncIterable<String> iterable)

Lecture

split is a direct port of FxTS's character-wise split, and that shows in its signature: it doesn't take a String at all — it takes an Iterable<String> of single characters, and walks it one character at a time, accumulating a piece until it sees one equal to sep. In Dart, the idiomatic way to get that character iterable is myString.split('') (Dart's own String.split with an empty pattern breaks a string into its individual characters).

A trailing separator produces a trailing empty string in the output, matching FxTS's behavior — 'a,b,' splits into ('a', 'b', ''), not just ('a', 'b'). There's no Fx chain form for split; call the top-level function (or splitAsync) directly.

Demo 1 · Basics

Demo 2 · Async

Try it yourself

Exercise: use split to break csv into color names on '|'.

Related: chunk — group by fixed size instead of separator · unicodeToList — get a proper character array (grapheme-aware) · join — the inverse operation