difference between indexOf and indexOfAny

S

srshashiranjan

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


Thanks in advance
 
M

mick

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
 
A

Arne Vajhøj

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();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top