using System; namespace Programs { public class Program { public static void Main(string[] args) { string str = @"stackoverflow(stack:stackoverflow)overstackflow(over:stackoverflow)"; Console.WriteLine(ExtractString(str)); } static string ExtractString(string s) { // You should check for errors in real-world code, omitted for brevity var startTag = "("; int startIndex = s.IndexOf(startTag) + startTag.Length; int endIndex = s.IndexOf(":", startIndex); return s.Substring(startIndex, endIndex - startIndex); } } }