Find the index of the last occurrence of any character in the string "is" within another string. : String Search « String « C# / CSharp Tutorial






using System;

class Sample {
    public static void Main() {

    string str = "this is a test.";
    int start;
    int at;
    string target = "is";
    char[] anyOf = target.ToCharArray();

    start = str.Length-1;
    at = str.LastIndexOfAny(anyOf);
    if (at > -1) 
        Console.Write(at);
    else
        Console.Write("(not found)");
        Console.Write("{0}{0}{0}", Environment.NewLine);
    }
}








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.