MemoryExtensionsSplit(ReadOnlySpanChar, ReadOnlySpanChar, StringSplitOptions) Method

Splits a string span into segments using the specified separator.

Definition

Namespace: Ookii.Common
Assembly: Ookii.Common (in Ookii.Common.dll) Version: 1.0.0+7c2900b8a16cd8ae46bdd79d8f105034712c5fa3
C#
public static MemoryExtensionsSplitEnumerable Split(
	this ReadOnlySpan<char> value,
	ReadOnlySpan<char> separator,
	StringSplitOptions options = StringSplitOptions.None
)

Parameters

value  ReadOnlySpanChar
The span to split.
separator  ReadOnlySpanChar
The separator that delimits the span segments.
options  StringSplitOptions  (Optional)
A bitwise combination of the enumeration values that specifies whether to trim substrings and include empty substrings.

Return Value

MemoryExtensionsSplitEnumerable
An object that can be used to enumerate the split segments.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type ReadOnlySpanChar. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method is similar to Split(String, StringSplitOptions), but operates on spans. It allows you to split a span into segments, and iterate the segments using a foreach loop, without allocating any memory.

Because the returned object is a ref struct, it implements the enumerable pattern, but does not implement the IEnumerableT interface. This means that while it can be used with foreach, it cannot be used with LINQ methods or other places that expect an IEnumerableT.

See Also