split(separator, maxsplit=∞, keepseparator=False, skip_empty=False) — split on a substring separator; unlike str.split, an empty separator leaves the text whole instead of raising.
rsplit(separator, maxsplit=∞, keepseparator=False, skip_empty=False) — same, scanning from the right.
split_byteset(separators, maxsplit=∞, keepseparator=False, skip_empty=False) — split on any single byte from the separators set.
rsplit_byteset(separators, maxsplit=∞, keepseparator=False, skip_empty=False) — same, from the right.
splitlines(keeplinebreaks=False, maxsplit=∞) — split on line breaks.
maxsplit caps the number of separators consumed, so 0 leaves the text whole, while a negative value or the default means unlimited. keepseparator keeps the matched separator attached to the parts. skip_empty drops zero-length parts, so a part keeping its separator is never dropped.
Without maxsplit and keepseparator, a one-byte separator, a byteset, and splitlines split the whole text in one native pass straight into the tape.
import stringzilla as szfor field in sz.String("2024-01-15").split_iter("-"): print(field) # 2024, then 01, then 15assert str(next(iter(sz.String("a/b/c").rsplit_iter("/")))) == "c"assert sum(1 for _ in sz.String("a,b,c").split_iter(",")) == 3
join(strings) concatenates strings with the String between every two, as str.join does, into a new String.
A Strings is read in place, any other iterable of str and bytes-like objects through a snapshot of it, and the result is measured first and written once.
import stringzilla as szassert str(sz.String(", ").join(["Ada", "Grace", "Linus"])) == "Ada, Grace, Linus"assert str(sz.String("\n").join(sz.String("a b c").split())) == "a\nb\nc"
Provides lazy evaluation of string splits without materializing all results.
Created by
String.split_iter()
String.rsplit_iter()
String.split_byteset_iter()
String.rsplit_byteset_iter()
Features
Memory-efficient: yields results one at a time
Forward and reverse iteration support
Character set and string separator support
Examples
>>> # split_iter streams parts lazily - prefer it over split() on large inputs:>>> for field in sz.String('2024-01-15').split_iter('-'):... print(field)20240115
Functions
partitionSplit the string into a 3-tuple around the first occurrence of a separator.