I would personally take the simplest approach: use BigInteger
to parse both values, and compare those results. That wouldn't be terribly efficient, but it would be very simple - and then you could benchmark to see whether it's fast enough.
Otherwise, you could find the effective length by ignoring leading zeroes - and if one number is longer than the other, then that's all you need to know. Or write a method to get the "effective" digit of a string which may be shorter, returning 0 if necessary, and then compare from the longer string's length downwards until one string gives a bigger value. Something like:
// Return the digit as a char to avoid bothering to convert digits to their
// numeric values.
private char GetEffectiveDigit(string text, int digitNumber)
{
int index = text.Length - digitNumber;
return index < 0 ? '0' : text[index];
}
private int CompareNumbers(string x, string y)
{
for (int i = int.Max(x.Length, y.Length); i >= 0; i--)
{
char xc = GetEffectiveDigit(x, i);
char yc = GetEffectiveDigit(y, i);
int comparison = xc.CompareTo(yc);
if (comparison != 0)
{
return comparison;
}
}
return 0;
}
Note that this doesn't check that it's a valid number at all, and it definitely doesn't attempt to handle negative numbers.