Cosmic Q&A
How can I get the index of any of the specified set of characters in a given string in C#?
Answer
We can get the index of any of the specified set of characters in a given string in C# using IndexOfAny method.
string word = "XMarksTheSpot";
// Get the index of any of the chars specified in the array.
Console.WriteLine(word.IndexOfAny(new char[] { 'a', 'e', 'i', 'o', 'u' }));
Share this page:
Report Error in Content