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);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uR2xvYmFsaXphdGlvbjsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljOwoKICAgIHB1YmxpYyBzdGF0aWMgY2xhc3MgRXh0ZW5zaW9ucwogICAgewogICAgICAgIHB1YmxpYyBzdGF0aWMgYm9vbCBDb250YWluc1N1YnN0cmluZyh0aGlzIHN0cmluZyBzdHJpbmcxLCBzdHJpbmcgc3RyaW5nMiwgaW50IG1pbkxlbmd0aCwgU3RyaW5nQ29tcGFyaXNvbiBjb21wYXJpc29uKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKG1pbkxlbmd0aCA8PSAwKSB0aHJvdyBuZXcgQXJndW1lbnRFeGNlcHRpb24oIk1pbmltdW0tbGVuZ3RoIG9mIHN1YnN0cmluZyBtdXN0IGJlIGdyZWF0ZXIgdGhhbiAwIiwgIm1pbkxlbmd0aCIpOwogICAgICAgICAgICBpZiAoc3RyaW5nLklzTnVsbE9yRW1wdHkoc3RyaW5nMSkgfHwgc3RyaW5nMS5MZW5ndGggPCBtaW5MZW5ndGgpIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgaWYgKHN0c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