ReadOnlySpanPolyfillExtensionLastIndexOf(ReadOnlySpan`1Char, String, StringComparison) Method

Specifies the zero-based index of the last occurrence of a specified string in span. A parameter specifies the type of search for the specified string.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public static int LastIndexOf(
	this ReadOnlySpan<char> span,
	string? value,
	StringComparison comparisonType
)

Parameters

span  ReadOnlySpanChar
The span to search.
value  String
The String to search for, or null.
comparisonType  StringComparison
One of the enumeration values that specifies the rules for the comparison.

Return Value

Int32
The zero-based index of value if that character sequence is found, or -1 if it is not. If value is Empty or null, the last index position in span is returned. In the specific case that span is Empty, that is 0.

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

The behavior of the method is identical to that of LastIndexOf(String, StringComparison) of the respective framework version. This has changed with .NET 5.0: Since then span.Length is returned if value is Empty.

Exceptions

ArgumentExceptioncomparisonType is not a defined value of the StringComparison enum.

See Also