fork download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. public static class Extensions
  7. {
  8. public static bool ContainsSubstring(this string string1, string string2, int minLength, StringComparison comparison)
  9. {
  10. if (minLength <= 0) throw new ArgumentException("Minimum-length of substring must be greater than 0", "minLength");
  11. if (string.IsNullOrEmpty(string1) || string1.Length < minLength) return false;
  12. if (string.IsNullOrEmpty(string2) || string2.Length < minLength) return false;
  13. for (int i = 0; i < string1.Length - minLength; i++)
  14. {
  15. string part1 = string1.Substring(i, minLength);
  16. if (string2.IndexOf(part1, comparison) > -1)
  17. return true;
  18. }
  19. return false;
  20. }
  21. }
  22.  
  23. public class Test
  24. {
  25. public static void Main()
  26. {
  27. string Text1 = "123bob456";
  28. string Text2 = "bobishere";
  29. bool contains = Text1.ContainsSubstring(Text2, 3, StringComparison.CurrentCultureIgnoreCase); // true
  30. Console.WriteLine(contains);
  31. }
  32. }
Success #stdin #stdout 0.05s 33960KB
stdin
Standard input is empty
stdout
True