The shortest sorting algorithm, I know of, is used. It parses the list and the leftmost entry is appended to the output. This entry is removed from the input and the search-append procedure is repeated, with the second, third... entries from left. The key is the comparison of the entries. It is done in the After(x,y) function, which returns true (1) if x is after y, and 0 otherwise. You can edit this function for other sorting criteria.
In this simple example the PreText(x) function finds the string preceding the first digit. If we compare two strings with the same PreText, we can remove it and compare the rest as numbers. If the PreText values are different, string comparisons are used.
#NoEnv
SetBatchLines -1
a = y0,x2,x10,x100,x1,x3, ; terminate with delimiter!
MsgBox % Sort(a,",")
Sort(x, delim="") {
IfEqual delim,, SetEnv delim, `n
x = %delim%%x%
Loop {
Loop Parse, x, %delim%
If (A_LoopField > "" and (A_Index = 2 or After(y,A_LoopField)))
y = %A_LoopField%
z = %z%%y%%delim%
StringReplace x, x, %delim%%y%%delim%, %delim%
IfEqual x,%delim%, Return z
}
}
After(x,y) {
p := PreText(x)
If (p <> PreText(y))
Return x>y
StringReplace x, x, %p%
StringReplace y, y, %p%
Return x>y
}
PreText(x) {
Loop Parse, x, 0123456789
Return A_LoopField
}The sorting algorithm is of quadratic time of the length of the list. With somewhat longer script we can sort faster. With my 2GHz laptop sorting 1000 entries took under 4 seconds with the above code, which should be enough for casual uses. If there is a need, I will post a longer but faster version, but with interpreted code one should not process millions of entries.If further letters follow the last digit, the After function reverts to string comparison, which results in file10a, file2, file3... It is not clear, what is the right order in this case. One could use the numbers only, requiring somewhat longer code. It is not hard to do some mods.




