using System.Collections.Generic;
static IEnumerable<string> substrings(string s, int length) {
for (int i = 0 ; i + length <= s.Length; i++) {
var ss = s.Substring(i, length);
if (!(ss.StartsWith(" ") || ss.EndsWith(" ")))
public static void Main()
var string1 = "images of canadian geese goslings";
var string2 = "Canadian geese with goslings pictures to choose from, with no signup needed";
for (int i = string1.Length; i>0 && string.IsNullOrEmpty(result); i--) {
foreach (string s in substrings(string1, i)) {
if (string2.IndexOf(s, StringComparison.CurrentCultureIgnoreCase) >= 0) {
if (string.IsNullOrEmpty(result))
Console.WriteLine("no common substrings found");
Console.WriteLine("'" + result + "'");
Console.WriteLine(count);