using System.Collections.Generic;
public static void Main()
Console.WriteLine(new AlphanumericVersionComparer().Compare("1a.2.b.3a", "1a.2.b.3b"));
public class AlphanumericVersionComparer : IComparer<string>
public int Compare(string x, string y)
if (x == null) throw new ArgumentNullException("x");
if (y == null) throw new ArgumentNullException("y");
string[] xParts = x.Split('.');
string[] yParts = y.Split('.');
AlphanumericComparer alphaNumComparer = new AlphanumericComparer();
for (int i = 0, n = Math.Max(xParts.Length, yParts.Length); i < n; i++)
int result = alphaNumComparer.Compare(xParts[i], yParts[i]);
System.Diagnostics.Debug.Fail("Not supposed to reach this code...");
public class AlphanumericComparer : IComparer<string>
public int Compare(string x, string y)
while (marker1 < len1 && marker2 < len2)
char[] space1 = new char[len1];
char[] space2 = new char[len2];
} while (char.IsDigit(ch1) == char.IsDigit(space1[0]));
} while (char.IsDigit(ch2) == char.IsDigit(space2[0]));
string str1 = new string(space1);
string str2 = new string(space2);
if (char.IsDigit(space1[0]) && char.IsDigit(space2[0]))
int thisNumericChunk = int.Parse(str1);
int thatNumericChunk = int.Parse(str2);
result = thisNumericChunk.CompareTo(thatNumericChunk);
result = str1.CompareTo(str2);