Search a sub string in a string: lastIndexOf : String Search « String « C# / CSharp Tutorial






using System; 
 
class MainClass { 
  public static void Main() { 
    string str = "abcdefghijk"; 
    int idx; 
 
    idx = str.LastIndexOf("def"); 
    Console.WriteLine("Index of last \"def\": " + idx); 
  }
}
Index of last "def": 3








5.18.String Search
5.18.1.Search a character in a string
5.18.2.Search a character in a string: lastindex
5.18.3.Search a sub string in a string
5.18.4.Search a sub string in a string: lastIndexOf
5.18.5.Search any characters in a string
5.18.6.String starts with and ends with
5.18.7.Search a string from the start or from the end
5.18.8.Use LastIndexOf(Char) to find the last directory separator character in a string and to extract the file name
5.18.9.Find the index of the last occurrence of any character in the string "is" within another string.