Search a string from the start or from the end : String Search « String « C# / CSharp Tutorial






using System;  
  
class MainClass {   
  public static void Main() {   
    string str1 = "ABCDEabcde1234567e890";   
  
    // search string 
    int idx = str1.IndexOf("e");  
    Console.WriteLine("Index of first occurrence of One: " + idx);  
    idx = str1.LastIndexOf("e");  
    Console.WriteLine("Index of last occurrence of One: " + idx);  
      
  }   
}
Index of first occurrence of One: 9
Index of last occurrence of One: 17








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.