using System.Collections.Generic;
public static void Main()
List<string> paths = new List<string>();
paths.Add(@"C:/Hello/World/This/Is/An/Example/Bla.cs");
paths.Add(@"C:/Hello/World/This/Is/Not/An/Example/");
paths.Add(@"C:/Hello/Earth/Bla/Bla/Bla");
List<string> order1 = paths.OrderBy(s => s).ToList();
foreach (string path in order1)
Console.WriteLine("Most common string here: {0}", sharedSubstring(order1[0], order1[order1.Count - 1]));
public static string sharedSubstring(string string1, string string2)
string ret = string.Empty;
while (string1.Substring(0, index) == string2.Substring(0, index))
ret = string1.Substring(0, index);