use the StartsWith() and EndsWith() methods to check if a string contains a specified substring at the start and end

image_pdfimage_print
   
 


using System;

class MainClass {

    public static void Main() {
        string[] myStrings = {"To", "be", "or", "not","to", "be"};
        string myString = String.Join(".", myStrings);        
        Console.WriteLine("myString = " + myString);
        if (myString.StartsWith("To")) {
            Console.WriteLine("myString starts with "To"");
        }
        if (myString.EndsWith("be")) {
            Console.WriteLine("myString ends with "be"");
        }

    
    }
}

    


This entry was posted in Data Types. Bookmark the permalink.