CSharp examples for Language Basics:string
Demonstrating StartsWith and EndsWith methods.
using System;//from ww w . ja v a2s. c o m class StringStartEnd { static void Main() { string[] strings = { "started", "starting", "ended", "ending" }; foreach (var element in strings) { if (element.StartsWith("st")) { Console.WriteLine($"\"{element}\" starts with \"st\""); } } Console.WriteLine(); // test every string to see if it ends with "ed" foreach (var element in strings) { if (element.EndsWith("ed")) { Console.WriteLine($"\"{element}\" ends with \"ed\""); } } Console.WriteLine(); } }