System.String.LastIndexOf Method

Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for the specified number of character positions. A parameter specifies the type of comparison to perform when searching for the specified string.


public int LastIndexOf (string value, int startIndex, int count, StringComparison comparisonType)


The string to seek.
The search starting position. The search proceeds from startIndex toward the beginning of this instance.
The number of character positions to examine.
One of the enumeration values that specifies the rules for the search.


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


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 search begins at the startIndex character position and proceeds backward until either value is found or count character positions have been examined. For example, if startIndex is string.Length - 1, the method searches backward count characters from the last character in the string.

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.


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