using System; using System.Globalization; using System.Linq; using System.Collections.Generic; public static class Extensions { public static bool ContainsSubstring(this string string1, string string2, int minLength, StringComparison comparison) { if (minLength <= 0) throw new ArgumentException("Minimum-length of substring must be greater than 0", "minLength"); if (string.IsNullOrEmpty(string1) || string1.Length < minLength) return false; if (string.IsNullOrEmpty(string2) || string2.Length < minLength) return false; for (int i = 0; i < string1.Length - minLength; i++) { string part1 = string1.Substring(i, minLength); if (string2.IndexOf(part1, comparison) > -1) return true; } return false; } } public class Test { public static void Main() { string Text1 = "123bob456"; string Text2 = "bobishere"; bool contains = Text1.ContainsSubstring(Text2, 3, StringComparison.CurrentCultureIgnoreCase); // true Console.WriteLine(contains); } }