C# String IndexOfAny(Char[])
Description
String IndexOfAny(Char[])
reports the zero-based index
of the first occurrence in this instance of any character in a specified array
of Unicode characters.
Syntax
String.IndexOfAny(Char[])
has the following syntax.
public int IndexOfAny(
char[] anyOf
)
Parameters
String.IndexOfAny(Char[])
has the following parameters.
anyOf
- A Unicode character array containing one or more characters to seek.
Returns
String.IndexOfAny(Char[])
method returns The zero-based index position of the first occurrence in this instance where
any character in anyOf was found; -1 if no character in anyOf was found.
Example
The following example uses the IndexOfAny method to check for invalid characters in a user entered string.
/*from w w w . java2 s.c o m*/
using System;
public class MainClass
{
public static void Main(String[] argv)
{
System.Console.WriteLine("java2s.com".IndexOfAny(new char[] { 'a' }));
}
}
The code above generates the following result.