C# String IndexOfAny(Char[], Int32)
Description
String IndexOfAny(Char[], Int32)
reports the zero-based
index of the first occurrence in this instance of any character in a specified
array of Unicode characters. The search starts at a specified character
position.
Syntax
String.IndexOfAny(Char[], Int32)
has the following syntax.
public int IndexOfAny(
char[] anyOf,
int startIndex
)
Parameters
String.IndexOfAny(Char[], Int32)
has the following parameters.
anyOf
- A Unicode character array containing one or more characters to seek.startIndex
- The search starting position.
Returns
String.IndexOfAny(Char[], Int32)
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
Sample for String.IndexOfAny(Char[], Int32)
//from w w w . j ava2 s.c o m
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/2;
at = str.IndexOfAny(anyOf, start);
if (at > -1)
Console.Write(at);
else
Console.Write("(not found)");
}
}
The code above generates the following result.