Can you pad the numbers in the strings with zeros?
If so, the library provided comparisons will work...
0100 < 0900 < 1001 < user1 < user2 < user11
So, the order you want is
- In alpha order
- If the first char is numaric grab the whole first number and compare as an int
And you say they are only alpha numaric, but were talking about * and # ... So, which is it?
Alright how about this (in psuedo code)
Code:
if(one starts with a digit and other doesn't)
return that the one with digit is smaller
if(first char of both are digits)
{
get the whole first number (all chars that are digits) from both
if the numbers are equal
continue
else return the result
}
else
{
compare the string, striping all numbers that may be in middle or end of string (storing them for comparison)
if(strings w/o nums equal)
compare the numbers you striped out
else return the inequality
}
Why is this sorted order so important, and why are there so many numbers in all different places in the string? It seems that there should be a little more consistancy to the strings in most applications... To be honest you may want to consider writing several small/simpler comparitors and just sort using each untill the order and sub order and sub-suborder are exactly as you want...
Is al10fred < al020fred or al020fred < al10fred
10 < 020 in numbers, but asciibetical and alphabetical (by most standards) 020 < 10.
Just some food for thought