String::LastIndexOf Method (String^)
Reports the zero-based index position of the last occurrence of a specified string within this instance.
Assembly: mscorlib (in mscorlib.dll)
The string to seek.
Index numbering starts from zero. That is, the first character in the string is at index zero and the last is at Length - 1.
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.
This method performs a word (case-sensitive and culture-sensitive) search using the current culture.
Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if value contains an ignorable character, the result is equivalent to searching with that character removed. If value consists only of one or more ignorable characters, the String::Length – 1, which represents the last index position in the current instance. In the following example, the method is used to find three substrings (a soft hyphen (U+00AD), a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on the .NET Framework 4 or later, in each case, because the soft hyphen is an ignorable character, the result is the same as if the soft hyphen had not been included in value. When searching for a soft hyphen only, the method returns 6 and 5. These values correspond to the index of the last character in the two strings.method always returns
Notes to Callers:
As explained in Best Practices for Using Strings in the .NET Framework, we recommend that you avoid calling string comparison methods that substitute default values and instead call methods that require parameters to be explicitly specified. To find the last index of a substring within a string instance by using the comparison rules of the current culture, call the LastIndexOf(String^, StringComparison) method overload with a value of StringComparison::CurrentCulture for its comparisonType parameter.
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 themethod to locate the start of the end tag.
Available since 4.5
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1