MemoryExtensions.Split(ReadOnlySpan<Char>, ReadOnlySpan<Char>, 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 MemoryExtensions.SplitEnumerable Split(
	this ReadOnlySpan<char> value,
	ReadOnlySpan<char> separator,
	StringSplitOptions options = StringSplitOptions.None
)

Parameters

value  ReadOnlySpan<Char>
The span to split.
separator  ReadOnlySpan<Char>
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

MemoryExtensions.SplitEnumerable
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 ReadOnlySpan<Char>. 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 IEnumerable<T> interface. This means that while it can be used with foreach, it cannot be used with LINQ methods or other places that expect an IEnumerable<T>.

See Also