Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

list sorting

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
334 Views, 4 Replies

list sorting

Hey Gang

 

Is it possible to sort the below list so that it is sequencial i.e.  "ID NO. 1" "ID NO.2" .....

 

("ID No. 1" "ID No. 10" "ID No. 11" "ID No. 12" "ID No. 13" "ID No. 14" "ID No. 5" "ID No. 6" "ID No. 7" "ID No. 8" "ID No. 9" "ID No. 2" "ID No. 3" "ID No. 4")

 

tia

 

Southie

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Found this on the search board thanks kent Cooper. I made a slight modification

 

(vl-sort

  '("ID No. 1" "ID No. 10" "ID No. 11" "ID No. 12" "ID No. 13" "ID No. 14" "ID No. 5" "ID No. 6" "ID No. 7" "ID No. 8" "ID No. 9" "ID No. 2" "ID No. 3" "ID No. 4")

 

  '(lambda (a b)

    (<

      (atoi (substr a (+ (vl-string-position (ascii " ") a 0 T) 2)))

      (atoi (substr b (+ (vl-string-position (ascii " ") b 0 T) 2)))

    ); <

  ); lambda

); vl-sort

Message 3 of 5
pbejse
in reply to: Anonymous

Another

 

(vl-sort lst
 '(lambda (a b / x)
    	(setq x (vl-string-mismatch a b))
    (< (atoi (substr a x))(atoi (substr b x))
     )
  )
)

 

Message 4 of 5
Anonymous
in reply to: Anonymous

pb thanks for the response learning that '(lambda (a b)... is a friend !!

 

Southie

 

Message 5 of 5
devitg
in reply to: pbejse

Thanks , nice routine , I had never seen the 

 

vl-string-mismatch

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost