System.String.LastIndexOf Method

Reports the zero-based index of the last occurrence of a specified string within the current string object. A parameter specifies the type of search to use for the specified string.

Syntax

public int LastIndexOf (string value, StringComparison comparisonType)

Parameters

value
The string to seek.
comparisonType
One of the enumeration values that specifies the rules for the search.

Returns

The zero-based starting index position of the value parameter if that string is found, or -1 if it is not. If value is string.Empty, the return value is the last index position in this instance.

Remarks

Index numbering starts from zero. That is, the first character in the string is at index zero and the last is at string.Length - 1.

The comparisonType parameter specifies to search for the value parameter using the current or invariant culture, using a case-sensitive or case-insensitive search, and using word or ordinal comparison rules.

The search begins at the last character position of this instance and proceeds backward toward the beginning until either value is found or the first character position has been examined.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0