using System.Collections.Generic;
public static void Main()
string[] arr = {"bla_c3", "bla_c2",
"bla_c4", "bla_c1", "bla_c10", "bla_c12", "bla_cab", "bla_ca10", "bla_ca1" };
Console.WriteLine("ORIGINAL");
Console.WriteLine("-- " + s);
for(int p=1;p<arr.Length-1;p++){
Console.WriteLine("LCP is " + lcp);
Console.WriteLine("ORDERED");
var strings = arr.OrderBy(s => s, new CustomComparer());
foreach(var s in strings)
Console.WriteLine("-- " + s);
public static string LCP(string str1, string str2){
if (str1.Length < str2.Length && str2.StartsWith(str1)) return str1;
if (str2.Length < str1.Length && str1.StartsWith(str2)) return str2;
for(int i=0; i<=str1.Length-1 && i<=str2.Length-1; i++){
return str1.Substring(0, lastIndex);
public class CustomComparer : IComparer<string>
private static string LCP(string str1, string str2){
if (str1.Length < str2.Length && str2.StartsWith(str1)) return str1;
if (str2.Length < str1.Length && str1.StartsWith(str2)) return str2;
for(int i=0; i<=str1.Length-1 && i<=str2.Length-1; i++){
return str1.Substring(0, lastIndex);
public int Compare(string s1, string s2)
s1 = s1.Substring(lcp.Length);
s2 = s2.Substring(lcp.Length);
if (string.IsNullOrEmpty(s1)) return -1;
if (string.IsNullOrEmpty(s2)) return 1;
xInt = int.TryParse(s1, out x);
yInt = int.TryParse(s2, out y);
if (this.SplitInt(s2, out y, out s2))
if (this.SplitInt(s1, out x, out s1))
private bool SplitInt(string sin, out int x, out string sout)
var numbers = Enumerable.Range(0, 10).Select(it => it.ToString());
var ie = sin.GetEnumerator();
while (ie.MoveNext() && numbers.Contains(ie.Current.ToString()))
sout = sin.Substring(i + 1);
sin = sin.Substring(0, i + 1);
int.TryParse(sin, out x);