struct SplitEnumerable The iterators are lazy and allocation-free: each is a ref struct enumerator yielding zero-copy ReadOnlySpan<byte> views, so a foreach never touches the heap.
The codepoint and segmentation iterators batch 64 boundaries per native call; the substring and byte-set splits and the match iterators advance one find at a time.
Policies are fluent methods on the returned value.
foreach (Rune rune in Sz.EnumerateRunes(text)) Use(rune); // cf. string.EnumerateRunes
foreach (var word in Sz.EnumerateWords(text)) Use(word); // also Graphemes/Sentences/LineBreaks
foreach (var field in Sz.Split(line, ","u8)) Use(field); // cf. string.Split, but zero-copy
foreach (var part in Sz.RSplit(path, "/"u8).WithMaxSplit(1)) Use(part); // from the end, at most one split
foreach (var token in Sz.SplitAny(text, separators)) Use(token); // split on any byte in a Byteset
foreach (var line in Sz.SplitWhitespaces(text).SkipEmpty()) Use(line); // collapse whitespace runs
foreach (long at in Sz.EnumerateMatches(haystack, "ab"u8)) Use(at); // every offset; .Overlapping() for overlaps
foreach (var m in Sz.EnumerateUncasedMatches(haystack, "ß"u8)) Use(m); // caseless; m.Offset, m.Length
var (before, separator, after) = Sz.Partition(text, "="u8); // split at the first "="WithMaxSplit(n) stops after n separators: 0 yields the whole text, and a negative n, the default, splits at every separator.
An empty separator yields the whole text, a trailing separator leaves a final empty segment unless .SkipEmpty(), and an empty needle matches at every offset up to and including the end, or at every codepoint boundary when uncased.
API
StructSplitEnumerableAllocation-free foreach source over split segments. See Sz.Split.4
Skip*SkipEmpty× 2Drop zero-length segments.
SplitEnumerable SkipSkipEmpty(); KeepSeparatorKeep the separator attached to each segment: the trailing separator when splitting forward, the leading separator when splitting in reverse.
SplitEnumerable KeepSeparator(); WithMaxSplitStop after maxSplit separators, leaving the rest as one final segment: 0 yields the whole text, and a negative count, the default, splits at every separator.
SplitEnumerable WithMaxSplit(long maxSplit); GetEnumeratorReturns an enumerator over the split segments.
SplitEnumerator GetEnumerator(); StructTokenSplitEnumerableAllocation-free foreach source over separator-token splits. See Sz.SplitWhitespaces.3
struct TokenSplitEnumerable WithSeparatorsAlso yield the separator runs, interleaved with the gaps (lossless reconstruction).
TokenSplitEnumerable WithSeparators(); OnlySeparatorsYield only the separator runs.
TokenSplitEnumerable OnlySeparators(); GetEnumeratorReturns an enumerator over the separator-token split spans.
TokenSplitEnumerator GetEnumerator();