muthu123 发表于 2022-7-6 11:01:07

List sorting- problem

Dear friends,
 
How can i sort this list
("RF-1" "RF1-10C" "RF1-2" "RF1-2A" "RF1-5" "RF2-10" "RF2-10A" "RF2-2B" "RF2-2C")
 
into
 
("RF-1""RF1-2" "RF1-2A" "RF1-5" "RF1-10C" "RF2-2B" "RF2-2C" "RF2-10" "RF2-10A")
 
Yours
Muthu

Lee Mac 发表于 2022-7-6 11:37:26

I collaborated with Gile a while back writing this:
 

(defun ArchSort ( lst / SplitStr comparable ) ;; Gile & Lee Mac (defun SplitStr ( str / lst test rslt num tmp )      (setq lst (vl-string->list str) test (chr (car lst)))      (if (< 47 (car lst) 58)   (setq num T)   )      (while (setq lst (cdr lst))   (if num       (cond         (         (= 46 (car lst))         (if (and (cadr lst)                  (setq tmp (strcat "0." (chr (cadr lst))))                  (numberp (read tmp)))             (setq rslt (cons (read test) rslt) test tmp lst (cdr lst))             (setq rslt (cons (read test) rslt) test "." num nil)         )         )         (         (< 47 (car lst) 58)         (setq test (strcat test (chr (car lst))))         )         (T         (setq rslt (cons (read test) rslt) test (chr (car lst)) num nil)         )       )       (if (< 47 (car lst) 58)         (setq rslt (cons test rslt) test (chr (car lst)) num T)         (setq test (strcat test (chr (car lst))))       )   )   )      (if num   (setq rslt (cons (read test) rslt))   (setq rslt (cons test rslt))   )      (reverse rslt) )(defun comparable ( e1 e2 )   (or (and (numberp e1) (numberp e2))       (= 'STR (type e1) (type e2))       (not e1) (not e2)   ) )(mapcar   (function (lambda ( x ) (nth x lst)))      (vl-sort-i (mapcar (function SplitStr) lst)   (function       (lambda ( x1 x2 / n1 n2 comp )         (while         (and             (setq comp (comparable (setq n1 (car x1))                                    (setq n2 (car x2))))             (= n1 n2)             (setq x1 (cdr x1) x2 (cdr x2))         )         )         (if comp (< n1 n2) (numberp n1))       )   )   ) ))

muthu123 发表于 2022-7-6 11:45:57

 
 
Thank you so much.
But the result will be
("RF1-2" "RF1-2A" "RF1-5" "RF1-10C" "RF2-2B" "RF2-2C" "RF2-10" "RF2-10A" "RF-1").
 
It is better it will be like this
 
("RF-1" "RF1-2" "RF1-2A" "RF1-5" "RF1-10C" "RF2-2B" "RF2-2C" "RF2-10" "RF2-10A")
 
Thank you.
 
Yours,
Muthu

Lee Mac 发表于 2022-7-6 12:09:11

Yes, of course as:
 

(acad_strlsort '("RF-" "RF"))==>>("RF" "RF-")
页: [1]
查看完整版本: List sorting- problem