Hi again guys,
I was trying to figure out a function that does this:
_$ (foo "Hi123SplitThis12.345String25-20") -> ("Hi" 123 "SplitThis" 12.345 "String" 25 "-" 20)
Basically breaking a string into a list of strings and numbers.
I've searched quite a while, but the closest result was from Lee's
LM:SplitString function:
_$ (LM:splitstring "Hi123SplitThis12.345String25-20")
("H" "i" 123 "S" "p" "l" "i" "t" "T" "h" "i" "s" 12.345 "S" "t" "r" "i" "n" "g" 25 "-" 20)
As you can see it does character breaking, and groups those that form potential numbers.
That looks good, but if one has alphabetical fragments of unknown length the 'nth' position of the number or the string fragment would be lost:
_$ (LM:splitstring "AB-420-HE5")
("A" "B" "-" 420 "-" "H" "E" 5)
_$ (LM:splitstring "ASB-430-HS56")
("A" "S" "B" "-" 430 "-" "H" "S" 56)
Atleast the labeling str patterns look more like this (where the
strlen varies).
And yea I know that I could filter out the numbers in a new list and process them, but thats not the point.
So when using his subfunction along with
this one (wow, he wrote the 2nd function aswell) :
; https://www.theswamp.org/index.php?topic=53354.msg580794#msg580794
(defun GroupListByFoo
( prd lst
/ rtn tmp
) ; Lee Mac )
)
); defun GroupListByFoo
I've managed to write a solution:
(GroupListByFoo
(LM:splitstring "Hi123SplitThis12.345String25-20")
)
)
("Hi" 123 "SplitThis" 12.345 "String" 25 "-" 20)
But honestly I think that the above approach sucks, due the amount of proccessing/manupulating a single string..
So any ideas to write a better one from scratch?
Does this sound like a {Challenge} ?