using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharpStringSearch { class Program { public void Run() { // Create 3 strings to work with string s1 = "http://www.bbc.co.uk"; string s2; string s3; int index; // Search for first substring s2 = s1.Substring(0, 4); Console.WriteLine("Substring of \"" + s1 + "\" from index 0 (INCLUSIVE) to 4 (EXCLUSIVE):"); Console.WriteLine(s2); // Search for next substring index = s1.LastIndexOf("/"); s2 = s1.Substring(index + 1, 3); Console.WriteLine("\nSubstring from index after the last '/' (INCLUSIVE) to 3 (EXCLUSIVE) of \"" + s1 + "\" :"); Console.WriteLine(s2); // Search for next substring index = s1.IndexOf("."); //Get the substring after the first dot s2 = s1.Substring(index + 1); s3 = s2.Substring(0, 3); Console.WriteLine("\nSubstring from index 0 (INCLUSIVE) to 3 (EXCLUSIVE) after the first dot in " + s1); Console.WriteLine(s3); // Search for next substring index = s2.IndexOf("."); s3 = s2.Substring(index + 1, 2); Console.WriteLine("\nSubstring from the index after the second dot (INCLUSIVE) to 2 (EXCLUSIVE) " + s1); Console.WriteLine(s3); // Search for last substring index = s1.LastIndexOf("."); s3 = s1.Substring(index + 1, 2); Console.WriteLine("\nSubstring from the index after the third dot (INCLUSIVE) to 2 (EXCLUSIVE) " + s1); Console.WriteLine(s3 + "\n"); } static void Main() { Program t = new Program(); t.Run(); Console.ReadLine(); } } }