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






using System; 
 
class MainClass { 
  public static void Main() { 
    string str = "abcdefghijk"; 
    int idx; 
 
    Console.WriteLine("str: " + str); 
 
    idx = str.IndexOf('h'); 
    Console.WriteLine("Index of first 'h': " + idx); 
 
  } 
}
str: abcdefghijk
Index of first 'h': 7








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.