Author Topic: [XDrX-Function(42)] string sort  (Read 271 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 516
[XDrX-Function(42)] string sort
« on: May 10, 2024, 09:39:23 PM »
xdrx-string-logical<

Used to compare two strings in logical order. This function is typically used to sort a list of files to ensure that the files are arranged in a logical order that humans understand, rather than a simple dictionary order.

example:

Command: (acad_strlsort (list "file200.txt" "file100.txt" "file10.txt" "file5.txt"))
("file10.txt" "file100.txt" "file200.txt" "file5.txt")


Command: (vl-sort (list "file200.txt" "file100.txt" "file10.txt" "file5.txt") '(lambda(x y)(xdrx-string-logical< x y)))
("file5.txt" "file10.txt" "file100.txt" "file200.txt")

Code - Auto/Visual Lisp: [Select]
  1. (defun xd::string:sortlist (strl)
  2.   (vl-sort strl '(lambda (x y) (xdrx_string_logical< x y)))
  3. )
  4.  
  5. ;assoc string list sort
  6.  
  7. (defun xd::string:assocsortlist (strl)
  8.   (vl-sort strl '(lambda (x y) (xdrx_string_logical< (car x)(car y))))
  9. )


xd::string:assocsortlist
_$

(("file100.txt" (1 2 3)) ("file0.txt" (1 2 3)) ("file20.txt" (1 2 3)) ("file300.txt" (1 2 3)))
(("file0.txt" (1 2 3)) ("file20.txt" (1 2 3)) ("file100.txt" (1 2 3)) ("file300.txt" (1 2 3)))
_$
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net