difference between indexOf and indexOfAny

  • Thread starter Thread starter srshashiranjan
  • Start date Start date
S

srshashiranjan

dear friends
Please tell me what is the difference between indexOf and
indexOfAny in c sharp.


Thanks in advance
 
dear friends
Please tell me what is the difference between indexOf and
indexOfAny in c sharp.

IndexOf finds the first index of a char
IndexOfAny finds the first index of any of the chars

mick
 
Please tell me what is the difference between indexOf and
indexOfAny in c sharp.

Other have already mentioned that it is pretty well documented.

But for illustration see the code below.

Arne

=============================

using System;

namespace E
{
public class Program
{
public static void Test(string s)
{
Console.WriteLine(s);
Console.WriteLine("IndexOf A = " + s.IndexOf('A'));
Console.WriteLine("IndexOf B = " + s.IndexOf('B'));
Console.WriteLine("IndexOf C = " + s.IndexOf('C'));
Console.WriteLine("IndexOfAny ABC = " + s.IndexOfAny(new
char[] { 'A', 'B', 'C' }));
}
public static void Main(string[] args)
{
Test("ABC");
Test("AX");
Test("XB");
Test("X");
Test("BA");
Console.ReadKey();
}
}
}
 
Back
Top