use the IndexOf() and LastIndexOf() methods to search for substrings and characters; : String Search : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » String Search »

 

use the IndexOf() and LastIndexOf() methods to search for substrings and characters;








    
 


using System;

class MainClass {

    public static void Main() {
        string[] myStrings = {"To", "be", "or", "not","to", "be"};
        string myString = String.Join(".", myStrings);        

        int index = myString.IndexOf("be");

        Console.WriteLine("\"be\" first occurs at index " + index + " of myString");
        index = myString.LastIndexOf("be");
        Console.WriteLine("\"be\" last occurs at index " + index + " of myString");
        index = myString.IndexOf('b');
        Console.WriteLine("'b' first occurs at index " + index + " of myString");
        index = myString.LastIndexOf('b');
        Console.WriteLine("'b' last occurs at index " + index + " of myString");


    
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» String Search