Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int Compare (string x, string y)
- {
- if (x == y)
- return 0;
- int xi = 0;
- int yi = 0;
- while (xi < x.Length && yi < y.Length) {
- while(xi < x.Length && char.IsWhiteSpace(x[xi])) xi++;
- while(yi < y.Length && char.IsWhiteSpace(y[yi])) yi++;
- if(char.IsDigit(x[xi]) && char.IsDigit(y[yi]))
- {
- string xDigits = "";
- do
- {
- xDigits += x[xi];
- xi++;
- }
- while(xi < x.Length && char.IsDigit(x[xi]));
- string yDigits = "";
- do
- {
- yDigits += y[yi];
- yi++;
- }
- while(yi < y.Length && char.IsDigit(y[yi]));
- int xVal = ParseDigits(xDigits);
- int yVal = ParseDigits(yDigits);
- if(xVal > yVal) return 1;
- else if (xVal < yVal) return -1;
- }
- else if(x[xi] != y[yi])
- {
- return x[xi].CompareTo(y[yi]);
- }
- else
- {
- xi++;
- yi++;
- }
- }
- return 0;
- }
- public static int ParseDigits (string digits)
- {
- string newDigits = "";
- foreach (char c in digits) {
- if (c >= '0' && c <= '9')
- newDigits += c;
- else if (c >= '\uFF10' && c <= '\uFF19')
- newDigits += (char)(c - '\uFF10' + '0');
- else if (c >= '\u0660' && c <= '\u0669')
- newDigits += (char)(c - '\u0660' + '0');
- else if (c >= '\u09E6' && c <= '\u09EF')
- newDigits += (char)(c - '\u09E6' + '0');
- }
- if (newDigits == "")
- return 0;
- else
- return int.Parse (newDigits);
- }
Advertisement
Add Comment
Please, Sign In to add comment