C# String LastIndexOf(String)

Description

String LastIndexOf(String) reports the zero-based index position of the last occurrence of a specified string within this instance.

Syntax

String.LastIndexOf(String) has the following syntax.


public int LastIndexOf(
  string value
)

Parameters

String.LastIndexOf(String) has the following parameters.

  • value - The string to seek.

Returns

String.LastIndexOf(String) method returns The zero-based starting 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.

Example


using System;//w  w  w .j a v  a  2 s .co  m

public class Example
{
   public static void Main()
   {
      string s1 = "ani\u00ADmal";
      string s2 = "animal";

      // Find the index of the last soft hyphen.
      Console.WriteLine(s1.LastIndexOf("\u00AD"));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version