StringExtensions.Enumerate(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Enumerates the items in the input String instance, as pairs of value/index values.
This extension should be used directly within a foreach
loop:
string text = "Hello, world!";
foreach (var item in text.Enumerate())
{
// Access the index and value of each item here...
int index = item.Index;
char value = item.Value;
}
The compiler will take care of properly setting up the foreach
loop with the type returned from this method.
public static Microsoft.Toolkit.HighPerformance.Enumerables.ReadOnlySpanEnumerable<char> Enumerate (this string text);
static member Enumerate : string -> Microsoft.Toolkit.HighPerformance.Enumerables.ReadOnlySpanEnumerable<char>
<Extension()>
Public Function Enumerate (text As String) As ReadOnlySpanEnumerable(Of Char)
Parameters
Returns
A wrapper type that will handle the value/index enumeration for text
.
Remarks
The returned ReadOnlySpanEnumerable<T> value shouldn't be used directly: use this extension in a foreach
loop.