Edit

Share via


ReadOnlySpanExtensions.Tokenize<T>(ReadOnlySpan<T>, T) Method

Definition

Tokenizes the values in the input ReadOnlySpan<T> instance using a specified separator. This extension should be used directly within a foreach loop:

ReadOnlySpan<char> text = "Hello, world!";

foreach (var token in text.Tokenize(','))
{
    // Access the tokens here...
}

The compiler will take care of properly setting up the foreach loop with the type returned from this method.

public static CommunityToolkit.HighPerformance.Enumerables.ReadOnlySpanTokenizer<T> Tokenize<T> (this ReadOnlySpan<T> span, T separator) where T : IEquatable<T>;
static member Tokenize : ReadOnlySpan<'T (requires 'T :> IEquatable<'T>)> * 'T -> CommunityToolkit.HighPerformance.Enumerables.ReadOnlySpanTokenizer<'T (requires 'T :> IEquatable<'T>)> (requires 'T :> IEquatable<'T>)
<Extension()>
Public Function Tokenize(Of T As IEquatable(Of T)) (span As ReadOnlySpan(Of T), separator As T) As ReadOnlySpanTokenizer(Of T)

Type Parameters

T

The type of items in the ReadOnlySpan<T> to tokenize.

Parameters

span
ReadOnlySpan<T>

The source ReadOnlySpan<T> to tokenize.

separator
T

The separator T item to use.

Returns

A wrapper type that will handle the tokenization for span.

Remarks

The returned ReadOnlySpanTokenizer<T> value shouldn't be used directly: use this extension in a foreach loop.

Applies to