I've numerous times come across the issue of sorting strings in a more "human way of thinking fashion"
I've played around with the different sorting predicates like 'lessp, 'alphaNumCmp, 'axlStrcmpAlpNum but none are really sorting in the way I would need. I had hoped the 'axlStrcmpAlpNum would do what I wanted, but mixed strings are a challenge.
Example (end sorting result that I would like)
I've come across some LISP code for this, but must admit that although I've done a lot of skill programming the code at the link below are a bit "black magic like" for me, it does not translate directly into a skill program
So maybe someone could shed som light on how to transform this into something usefull in Skill.
Hint: http://www.davekoelle.com/alphanum.html has a number of other language implementations for the same type of sorting, it actually explain and illustrate the problem very nicely.
Thank you very much in advance
Based on the Perl example I came up with the following code. However it (and the Perl) gives a different result to your requirement:
defun( HumanCmp (str1, str2)
;split strings into chunks
a = Chunkify(str1)
b = Chunkify(str2)
;while we have chunks to compare.
while(a && b
when(alphaNumCmp(car(a), car(b), t) < 0, return(t)); return t if b > a
a = cdr(a), b = cdr(b)
; split on character type transitions
defun( Chunkify (str)
let((chunk, chunks, prevCh)
foreach(ch, parseString(str, "")
(!prevCh, chunk = ch)
(type(readstring(ch)) != type(readstring(prevCh)), chunks = cons(chunk, chunks), chunk = ch)
(t, chunk = strcat(chunk, ch))
prevCh = ch
when(chunk, reverse(cons(chunk, chunks)))
; sort('("11235a" "11235f" "111a32" "abc211" "xyz211" "22" "111234" "111237" "112323"), 'HumanCmp)
; Ole wants: ("22" "111234" "111237" "111a32" "112323" "11235a" "11235f" "abc211" "xyz211")
; I get: ("22" "111a32" "11235a" "11235f" "111234" "111237" "112323" "abc211" "xyz211")
Thank you very much, I can see your point about sort
Not sure how I'll fix that but thanks for your code, the first challenge that I did not really see how to solve was the chunkify function, but that works nicely, so now I need to figure out how to do a sort that acts they way I need it to work :-)
Thank you for your input on this, I got some code from a long time friend that I've been able to convert into something that can be used.
I'll try your method to figure out if that works better for me. I'll however need to check for length since any length text must be after numbers, so "aa" will be after any string starting with a number.
I'm in the same boat as you with numbers to strings, only aware of sprintf.