Mega Code Archive

 
Categories / C# Tutorial / String
 

Search any characters in a string

using System;    class MainClass {    public static void Main() {      string str = "abcdefghijk";      int idx;        char[] chrs = { 'a', 'b', 'c' };      idx = str.IndexOfAny(chrs);      Console.WriteLine("Index of first 'a', 'b', or 'c': " + idx);    } } Index of first 'a', 'b', or 'c': 0