use the StartsWith() and EndsWith() methods to check if a string contains a specified substring at the start and end
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\"");
}
}
}
Related examples in the same category