![]() |
VOOZH | about |
In C#, IndexOfAny() method is a String Method. It is used to search the specified character index present in the string which will be the first occurrence from start index. It returns index as an integer value. This method can be overloaded by changing the number of arguments passed to it.
This method will take a single parameter which is the character array containing one or more characters to search. It will search from the start index i.e. from 0 by default and returns -1 if no character in ch was found.
Syntax:
public int IndexOfAny(char[] ch)
Example: Program to demonstrate the public int IndexOfAny(char[] ch) method. The IndexOfAny method will search characters from the start to end of the string and return integer value as position which is the first occurrence of that character.
Output:
Given String : GeeksForGeeks 5 2 Not Found
This method uses the zero-based index of the first occurrence in the current instance of any character in a specified array of characters. The search starts from a specified character position.
Syntax:
public int IndexOfAny(char[] ch, int startIndex)
Example: Program to demonstrate the public int IndexOfAny(char[] ch, int startIndex) method. The IndexOfAny method will search characters from the start to specified startIndex to end of the string and return integer value as position which is the first occurrence of that character.
Output:
Given String : GeeksForGeeks 13 10 Not Found
This method uses the zero-based index of the first occurrence in the current instance of any character in a specified array of characters. The search starts from the specified character position and examines a specified number of character positions.
Syntax:
public int IndexOfAny(char[] ch, int startIndex, int count)
Example : Program to demonstrate the public int IndexOfAny( char[] ch, int startIndex, int count) method. This IndexOfAny method will search the characters from specified index to specified index + (count – 1) of the string where count is the number of the characters to examine and then return integer value as position which is the first occurrence of that character.
Output:
Given String : GeeksForGeeks -1 10 6
Important Points to Remember:
References: