Use the IndexOfAny() and LastIndexOfAny() methods to search for character arrays in a string : String : String C# Examples


C# Examples » String » String »

 

Use the IndexOfAny() and LastIndexOfAny() methods to search for character arrays in a string









    
using  System;

class  MainClass
{

    public  static  void  Main()
    {
        string[]  myStrings  =  {"To",  "be",  "or",  "not",  "to",  "be"};
        string  myString  =  String.Join(".",  myStrings);      
        
        char[]  myChars  =  {'b',  'e'};
        int  index  =  myString.IndexOfAny(myChars);
        Console.WriteLine("'b'  and  'e'  occur  at  index  "  +  index  +  "  of  myString");
        index  =  myString.LastIndexOfAny(myChars);
        Console.WriteLine("'b'  and  'e'  last  occur  at  index  "  +  index  +  "  of  myString");

    }

}
    
   
  
   



Output

'b' and 'e' occur at index 3 of myString
'b' and 'e' last occur at index 17 of myString


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String