Visual LISP, AutoLISP and General Customization

Reply
Mentor
Posts: 291
Registered: ‎03-15-2007
Message 1 of 5 (185 Views)

list sorting

185 Views, 4 Replies
10-19-2012 10:39 AM

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

Mentor
Posts: 291
Registered: ‎03-15-2007
Message 2 of 5 (173 Views)

Re: list sorting

10-19-2012 11:38 AM in reply to: southie

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

*Expert Elite*
Posts: 2,370
Registered: ‎11-24-2009
Message 3 of 5 (155 Views)

Re: list sorting

10-19-2012 07:17 PM in reply to: southie

Another

 

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

 

Mentor
Posts: 291
Registered: ‎03-15-2007
Message 4 of 5 (152 Views)

Re: list sorting

10-19-2012 07:35 PM in reply to: southie

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

 

Southie

 

Mentor
Posts: 1,682
Registered: ‎03-14-2004
Message 5 of 5 (116 Views)

Re: list sorting

10-21-2012 08:30 PM in reply to: pbejse

Thanks , nice routine , I had never seen the 

 

vl-string-mismatch

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community