String::LastIndexOf Method (String)

Reports the zero-based index position of the last occurrence of a specified string within this instance.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

No code example is currently available or this language may not be supported.

Parameters

value
Type: System::String
The string to seek.

Return Value

Type: System::Int32
The zero-based index position of value 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.

ExceptionCondition
ArgumentNullException

value is nullptr.

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

This method performs a word (case-sensitive and culture-sensitive) search using the current culture. The search begins at the last character position of this instance and proceeds backward, until either value is found or the first character position has been examined.

Notes to Callers

Starting in Silverlight 4, the behavior of the String::LastIndexOf(String) method has changed. In Silverlight 4, it performs a case-sensitive and culture-sensitive comparison using the current culture to find the last occurrence of value. This conforms to the behavior of the String::LastIndexOf(String) method in the full .NET Framework. In Silverlight 2 and Silverlight 3, String::LastIndexOf(String) performs an ordinal comparison. If the common language runtime determines that a Silverlight-based application was compiled against Silverlight 2 or Silverlight 3, it performs an ordinal comparison; otherwise, it performs a culture-sensitive comparison.

The following example removes opening and closing HTML tags from a string if the tags begin and end the string. If a string ends with a closing bracket character (">"), the example uses the LastIndexOf method to locate the start of the end tag.

No code example is currently available or this language may not be supported.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: