;;Usage (SortStringWithNumberAsNumber '("A9" "A1" "A10" "B11" "B2" "B05"))
;;Return ("A1" "A9" "A10" "B2" "B05" "B11")
(defun SortStringWithNumberAsNumber (ListOfString)
;;;Function Normalize (add 0 befor number) number in string
;;; Count normalize symbols set in variable count
(defun NormalizeNumberInString (str / ch i pat ret count buf)
(setq i 0
pat '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
ret ""
count 4 ;_Count normalize symbols
) ;_ end of setq
(while (/= (setq ch (substr str (setq i (1+ i)) 1)) "")
(if (vl-position ch pat)
(progn
(setq buf ch) ;_ end of setq
(while
(vl-position (setq ch (substr str (setq i (1+ i)) 1)) pat)
(setq buf (strcat buf ch))
) ;_ end of while
(while (< (strlen buf) count) (setq buf (strcat "0" buf)))
(setq ret (strcat ret buf))
) ;_ end of progn
) ;_ end of if
(setq ret (strcat ret ch))
) ;_ end of while
ret
) ;_ end of defun
(vl-load-com)
(mapcar '(lambda (x) (nth x ListOfString))
(vl-sort-i (mapcar 'NormalizeNumberInString ListOfString)
'<
) ;_ end of VL-SORT-I
) ;_ end of mapcar
) ;_ end of defun
Usage(setq lst (list "PN375-A10.dwg"
"PN375-A9.dwg"
"PN375-A04.dwg"
"PN375-A555.dwg"
"PN375-D1.dwg"
"PN375-D10.dwg"
"PN375-D14.dwg"
"PN375-D2.dwg"
"PN375-D22.dwg"
"PN375-D7r3.dwg"
"PN375-DB.dwg"
"PN375-DB10a.dwg"
"PN375-DB9.dwg"))
(mapcar '(lambda(x)(terpri)(princ x))
(SortStringWithNumberAsNumber lst))
Return;-------------------------------------------------------------------------------
; win_sort - Windows type of sort function
; Arguments: 1
; List@ = List of strings or filenames
; Returns: List of strings sorted similar to how Windows sorts files
;-------------------------------------------------------------------------------
(defun win_sort (Original@ / AlphaSort@ Cnt# Compare$ First Item List@ Loop
Next$ Num# NumSort@ NumStrings@ Passed Prefix$ Prefixes@ PrefixList@
PrefixSort@ Previous$ SortLenghts@ SortList@ Str$)
(setq Passed t)
(if (= (type Original@) 'LIST)
(foreach Item Original@ (if (/= (type Item) 'STR) (setq Passed nil)))
(setq Passed nil)
);if
(if (not Passed)
(progn (princ "\nUsage: (win_sort <list of strings>)") (exit))
);if
(setq Original@ (acad_strlsort Original@))
(setq AlphaSort@ (mapcar 'strcase Original@))
(setq Num# 0 Next$ (chr 160));a unique character
(repeat (length AlphaSort@)
(setq Previous$ Next$
Next$ (nth Num# AlphaSort@)
Prefix$ nil
Cnt# 1
);setq
(if (not (wcmatch (substr Next$ 1 1) "#"))
(repeat (strlen Next$)
(setq Str$ (substr Next$ 1 Cnt#)
Compare$ (strcat Str$ "*")
);setq
(if (and (wcmatch Previous$ Compare$)(not (wcmatch (substr Str$ (strlen Str$)) "#")))
(setq Prefix$ Str$)
);if
(setq Cnt# (1+ Cnt#))
);repeat
);if
(if Prefix$
(progn
(setq Compare$ (strcat Prefix$ "#*"))
(if (and (wcmatch Previous$ Compare$)(wcmatch Next$ Compare$))
(setq Passed t)
(setq Passed nil)
);if
);progn
);if
(if (and Passed Prefix$ (not (member Prefix$ Prefixes@)))
(setq Prefixes@ (append Prefixes@ (list Prefix$)))
);if
(setq Num# (1+ Num#))
);repeat
(if Prefixes@
(progn
(if (> (length Prefixes@) 1)
(progn
(setq Num# 1 List@ (cons (nth 0 Prefixes@) (append Prefixes@ (list (last Prefixes@)))))
(repeat (length Prefixes@)
(setq Compare$ (strcat (nth Num# List@) "*"))
(if (and (wcmatch (nth (1- Num#) List@) Compare$)(wcmatch (nth (1+ Num#) List@) Compare$))
(setq Prefixes@ (vl-remove (nth Num# List@) Prefixes@))
);if
(setq Num# (1+ Num#))
);repeat
);progn
);if
(setq SortLenghts@ (reverse (number_sort (mapcar 'strlen Prefixes@))))
(setq List@ Prefixes@)
(foreach Num# SortLenghts@
(setq First t)
(foreach Str$ List@
(if (and (= (strlen Str$) Num#) First)
(setq First nil
List@ (vl-remove Str$ List@)
PrefixSort@ (append PrefixSort@ (list Str$))
);setq
);if
);foreach
);foreach
(setq Prefixes@ (mapcar 'list PrefixSort@))
(setq List@ AlphaSort@ Num# 0)
(foreach Prefix$ PrefixSort@
(setq Compare$ (strcat Prefix$ "#*")
PrefixList@ (nth Num# Prefixes@)
First t
);setq
(foreach Str$ List@
(if (wcmatch Str$ Compare$)
(progn
(if First
(setq PrefixList@ (append PrefixList@ (list (vl-position Str$ AlphaSort@)))
First nil
);setq
);if
(setq List@ (vl-remove Str$ List@)
Str$ (substr Str$ (1+ (strlen Prefix$)))
PrefixList@ (append PrefixList@ (list Str$))
);setq
);if
);if
);foreach
(setq Prefixes@ (change_nth Num# PrefixList@ Prefixes@))
(setq Num# (1+ Num#))
);foreach
(foreach PrefixList@ Prefixes@
(setq NumStrings@ (cddr PrefixList@)
NumSort@ (number_sort (mapcar 'atoi NumStrings@))
List@ nil
);setq
(foreach Num# NumSort@
(setq Loop t Cnt# 0)
(while Loop
(setq Str$ (nth Cnt# NumStrings@))
(if (= (atoi Str$) Num#)
(setq NumStrings@ (delete_nth Cnt# NumStrings@)
Str$ (strcat (nth 0 PrefixList@) Str$)
List@ (append List@ (list Str$))
Loop nil
);setq
);if
(setq Cnt# (1+ Cnt#))
);while
);foreach
(setq Num# (nth 1 PrefixList@) SortList@ Original@)
(foreach Str$ List@
(setq Str$ (nth (vl-position Str$ AlphaSort@) Original@))
(setq SortList@ (change_nth Num# Str$ SortList@))
(setq Num# (1+ Num#))
);foreach
(setq Original@ SortList@)
);foreach
);progn
);if
(foreach Str$ AlphaSort@
(if (wcmatch (substr Str$ 1 1) "#")
(setq NumStrings@ (append NumStrings@ (list Str$)))
);if
);foreach
(if NumStrings@
(progn
(setq NumSort@ (number_sort (mapcar 'atoi NumStrings@))
List@ nil
);setq
(foreach Num# NumSort@
(setq Loop t Cnt# 0)
(while Loop
(setq Str$ (nth Cnt# NumStrings@))
(if (= (atoi Str$) Num#)
(setq NumStrings@ (delete_nth Cnt# NumStrings@)
List@ (append List@ (list Str$))
Loop nil
);setq
);if
(setq Cnt# (1+ Cnt#))
);while
);foreach
(setq Num# 0 SortList@ Original@)
(foreach Str$ List@
(setq Str$ (nth (vl-position Str$ AlphaSort@) Original@))
(setq SortList@ (change_nth Num# Str$ SortList@))
(setq Num# (1+ Num#))
);foreach
(setq Original@ SortList@)
);progn
);if
Original@
);defun win_sort
;-------------------------------------------------------------------------------
; number_sort - Sorts list of numbers
; Arguments: 1
; List@ = List of numbers
; Returns: List of sorted numbers
;-------------------------------------------------------------------------------
(defun number_sort (List@ / High~ Item~ List1@ List2@ Low~ NewList@ Passed Swap~)
(setq Passed t)
(if (= (type List@) 'LIST)
(foreach Item~ List@ (if (not (numberp Item~)) (setq Passed nil)))
(setq Passed nil)
);if
(if (not Passed)
(progn (princ "\nUsage: (number_sort <list of numbers>)") (exit))
);if
(repeat (/ (length List@) 2)
(setq Low~ (car List@) High~ nil NewList@ nil)
(foreach Item~ (cdr List@)
(and (< Item~ Low~) (setq Swap~ Low~ Low~ Item~ Item~ Swap~))
(and (> Item~ High~) (setq Swap~ High~ High~ Item~ Item~ Swap~))
(setq NewList@ (cons Item~ NewList@))
);foreach
(setq List1@ (cons Low~ List1@) List2@ (cons High~ List2@) List@ (cdr (reverse NewList@)))
);repeat
(append (reverse List1@) List@ List2@)
);defun number_sort
;-------------------------------------------------------------------------------
; Change_nth - Changes the nth item in a list with a new item value.
; Arguments: 3
; Num# = Nth number in list to change
; Value = New item value to change to
; OldList@ = List to change item value
; Returns: A list with the nth item value changed.
;-------------------------------------------------------------------------------
(defun Change_nth (Num# Value OldList@)
(if (<= 0 Num# (1- (length OldList@)))
(if (> Num# 0)
(cons (car OldList@) (Change_nth (1- Num#) Value (cdr OldList@)))
(cons Value (cdr OldList@))
);if
OldList@
);if
);defun Change_nth
;-------------------------------------------------------------------------------
; Delete_nth - Deletes the nth item from a list.
; Arguments: 2
; Num# = Nth number in list to delete
; OldList@ = List to delete the nth item
; Returns: A list with the nth item deleted.
;-------------------------------------------------------------------------------
(defun Delete_nth (Num# OldList@)
(setq Num# (1+ Num#))
(vl-remove-if '(lambda (x) (zerop (setq Num# (1- Num#)))) OldList@)
);defun Delete_nth
;-------------------------------------------------------------------------------
;;Usage (SortStringWithNumberAsNumber '("A9" "A1" "A10" "B11" "B2" "B05"))
;;Return ("A1" "A9" "A10" "B2" "B05" "B11")
(defun SortStringWithNumberAsNumber1 (ListOfString)
;;;Function Normalize (add 0 befor number) number in string
;;; Count normalize symbols set in variable count
(defun NormalizeNumberInString (str / ch i pat ret count buf)
(setq i 0
pat '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
ret ""
count 4 ;_Count normalize symbols
) ;_ end of setq
(while (/= (setq ch (substr str (setq i (1+ i)) 1)) "")
(if (vl-position ch pat)
(progn
(setq buf ch) ;_ end of setq
(while
(vl-position (setq ch (substr str (setq i (1+ i)) 1)) pat)
(setq buf (strcat buf ch))
) ;_ end of while
(while (< (strlen buf) count) (setq buf (strcat "0" buf)))
(setq ret (strcat ret buf))
) ;_ end of progn
) ;_ end of if
(setq ret (strcat ret ch))
) ;_ end of while
ret
) ;_ end of defun
(vl-load-com)
(mapcar '(lambda (x) (nth x ListOfString))
(vl-sort-i (mapcar 'NormalizeNumberInString (mapcar 'strcase ListOfString))
'<
) ;_ end of VL-SORT-I
) ;_ end of mapcar
) ;_ end of defun
Test(setq Lst (list "1-C4.dwg" "7-b7.dwg" "11-C4.dwg" "2-b3.dwg" "2-c2.dwg" "22-b2.dwg" "pn374-x9.dwg" "pn374-z9.dwg" "Pn375-A10.dwg" "pN375-A9.dwg" "pn375-D1.dwg" "PN375-D10.dwg" "pN375-D2r3.dwg" "pn375-D22.dwg" "qr86-007.dwg" "pN375-DB.dwg" "pn375-DB10a.dwg" "PN375-DB9.dwg"))
(mapcar '(lambda(x)(terpri)(princ x))
(SortStringWithNumberAsNumber1 lst))
Result;-------------------------------------------------------------------------------
(defun c:SortDemo1 (/ Filename$ OriginalList@ PathFilename$ SortedList@)
(princ "\nSelect a drawing in a folder for Folder name:")(princ)
(if (not *LastFolder$)
(setq *LastFolder$ (getvar "DWGPREFIX"))
);if
(if (setq PathFilename$ (getfiled " Select a drawing in a folder for Folder name" *LastFolder$ "dwg" 2))
(setq *LastFolder$ (strcat (vl-filename-directory PathFilename$) "\\"))
(exit)
);if
(textscr)
(princ (strcat "\n" *LastFolder$))
(setq OriginalList@ (vl-directory-files *LastFolder$ "*.dwg" 1))
(princ (strcat "\n" (chr 160) "\nOriginal list:\n--------------"))
(foreach Filename$ OriginalList@
(princ "\n")(princ Filename$)
);foreach
;Here you can change the sort function name that you are testing
(setq SortedList@ (SortStringWithNumberAsNumber1 (vl-directory-files *LastFolder$ "*.dwg" 1)))
(princ (strcat "\n" (chr 160) "\nSorted list:\n------------"))
(foreach Filename$ SortedList@
(princ "\n")(princ Filename$)
);foreach
(princ)
);defun c:SortDemo1
;-------------------------------------------------------------------------------
(defun c:SortDemo2 (/ Filename$ OriginalList@ PathFilename$ SortedList@)
(princ "\nSelect a drawing in a folder for Folder name:")(princ)
(if (not *LastFolder$)
(setq *LastFolder$ (getvar "DWGPREFIX"))
);if
(if (setq PathFilename$ (getfiled " Select a drawing in a folder for Folder name" *LastFolder$ "dwg" 2))
(setq *LastFolder$ (strcat (vl-filename-directory PathFilename$) "\\"))
(exit)
);if
(textscr)
(princ (strcat "\n" *LastFolder$))
(setq OriginalList@ (vl-directory-files *LastFolder$ "*.dwg" 1))
(princ (strcat "\n" (chr 160) "\nOriginal list:\n--------------"))
(foreach Filename$ OriginalList@
(princ "\n")(princ Filename$)
);foreach
;Here you can change the sort function name that you are testing
(setq SortedList@ (win_sort (vl-directory-files *LastFolder$ "*.dwg" 1)))
(princ (strcat "\n" (chr 160) "\nSorted list:\n------------"))
(foreach Filename$ SortedList@
(princ "\n")(princ Filename$)
);foreach
(princ)
);defun c:SortDemo2
;-------------------------------------------------------------------------------
;; By VVW -- 05.20.07 mods by CAB
;;Usage (SortStringWithNumberAsNumber '("A9" "A1" "A10" "B11" "B2" "B05") nil)
;; CAB added Ignore Case Flag as an argument
;;Return ("A1" "A9" "A10" "B2" "B05" "B11")
(defun SortStringWithNumberAsNumber (ListOfString IgnoreCase / NorStrs count
NormalizeNumberInString getcount)
;;;Function Normalize (add 0 befor number) number in string
;;; Count normalize symbols set in variable count
;;; CAB added count as an argument
(defun NormalizeNumberInString (str count / ch i pat ret buf)
(setq i 0
pat '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
ret ""
) ;_ end of setq
(while (/= (setq ch (substr str (setq i (1+ i)) 1)) "")
(if (vl-position ch pat)
(progn
(setq buf ch) ;_ end of setq
(while
(vl-position (setq ch (substr str (setq i (1+ i)) 1)) pat)
(setq buf (strcat buf ch))
) ;_ end of while
(while (< (strlen buf) count) (setq buf (strcat "0" buf)))
(setq ret (strcat ret buf))
) ;_ end of progn
) ;_ end of if
(setq ret (strcat ret ch))
) ;_ end of while
ret
) ;_ end of defun
;;-------------------------------------------------
;; function to Count the longest number in string
;; CAB added to get the correct COUNT
(defun getcount (lst / count pat)
(setq count 0)
(setq pat '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
(mapcar
'(lambda (str / i maxlen ch)
(setq i 0 maxlen 0)
(while (/= (setq ch (substr str (setq i (1+ i)) 1)) "")
(if (vl-position ch pat) ; number
(setq maxlen (1+ maxlen))
(setq count (max count maxlen) maxlen 0)
)
)
)
Lst
)
count
)
;;===============================================
(setq count (GetCount ListOfString)
NorStrs (mapcar '(lambda (x) (NormalizeNumberInString x count))
ListOfString)
)
(and IgnoreCase (setq NorStrs (mapcar 'strcase NorStrs)))
(mapcar '(lambda (x) (nth x ListOfString)) (vl-sort-i NorStrs '<))
) ;_ end of defun
;;Published http://www.theswamp.org/index.php?topic=16564.0
;;By VVA -- 05.20.07 mods by CAB
;;Usage (SortStringWithNumberAsNumber '("A9" "A1" "A10" "B11" "B2" "B05") nil)
;;With ignore case (SortStringWithNumberAsNumber '("A9" "A1" "A10" "B11" "B2" "B05") t)
;; CAB added Ignore Case Flag as an argument
;;Return ("A1" "A9" "A10" "B2" "B05" "B11")
(defun SortStringWithNumberAsNumber (ListOfString IgnoreCase / NorStrs count)
;;;Function Normalize (add 0 befor number) number in string
;;; Count normalize symbols set in variable count
;;; CAB added count as an argument
(defun NormalizeNumberInString (str count / ch i pat ret buf)
(setq i 0
pat '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
ret ""
) ;_ end of setq
(while (/= (setq ch (substr str (setq i (1+ i)) 1)) "")
(if (vl-position ch pat)
(progn
(setq buf ch) ;_ end of setq
(while
(vl-position (setq ch (substr str (setq i (1+ i)) 1)) pat)
(setq buf (strcat buf ch))
) ;_ end of while
(while (< (strlen buf) count) (setq buf (strcat "0" buf)))
(setq ret (strcat ret buf))
) ;_ end of progn
) ;_ end of if
(setq ret (strcat ret ch))
) ;_ end of while
ret
) ;_ end of defun
;;-------------------------------------------------
;; function to Count the longest number in string
;; CAB added to get the correct COUNT
(defun getcount (lst / count pat)
(setq count 0)
(setq pat '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
(mapcar
'(lambda (str / i maxlen ch)
(setq i 0 maxlen 0)
(while (/= (setq ch (substr str (setq i (1+ i)) 1)) "")
(if (vl-position ch pat) ; number
(setq maxlen (1+ maxlen))
(setq count (max count maxlen) maxlen 0)
)
)
)
Lst
)
count
)
;;===============================================
(setq count (GetCount ListOfString)
NorStrs (mapcar '(lambda (x) (NormalizeNumberInString x count))
ListOfString)
)
(and IgnoreCase (setq NorStrs (mapcar 'strcase NorStrs)))
(mapcar '(lambda (x) (nth x ListOfString)) (vl-sort-i NorStrs '<))
) ;_ end of defun
;;Published http://www.theswamp.org/index.php?topic=16564.0
;;By VVA -- 05.20.07 mods by CAB
;;Usage (SortStringWithNumberAsNumber '("A9" "A1" "A10" "B11" "B2" "B05") nil)
;;With ignore case (SortStringWithNumberAsNumber '("A9" "A1" "A10" "B11" "B2" "B05") t)
;; CAB added Ignore Case Flag as an argument
;;Return ("A1" "A9" "A10" "B2" "B05" "B11")
(defun SortStringWithNumberAsNumber (ListOfString IgnoreCase / NorStrs count)
;;;Function Normalize (add 0 befor number) number in string
;;; Count normalize symbols set in variable count
;;; CAB added count as an argument
(defun NormalizeNumberInString (str count / ch i pat ret buf)
(setq i 0
pat '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")
ret ""
) ;_ end of setq
(while (/= (setq ch (substr str (setq i (1+ i)) 1)) "")
(if (vl-position ch pat)
(progn
(setq buf ch) ;_ end of setq
(while
(vl-position (setq ch (substr str (setq i (1+ i)) 1)) pat)
(setq buf (strcat buf ch))
) ;_ end of while
(while (< (strlen buf) count) (setq buf (strcat "0" buf)))
(setq ret (strcat ret buf))
) ;_ end of progn
) ;_ end of if
(setq ret (strcat ret ch))
) ;_ end of while
ret
) ;_ end of defun
;;-------------------------------------------------
;; function to Count the longest number in string
;; CAB added to get the correct COUNT
(defun getcount (lst / count pat)
(setq count 0)
(setq pat '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9"))
(mapcar
'(lambda (str / i maxlen ch)
(setq i 0 maxlen 0)
(while (/= (setq ch (substr str (setq i (1+ i)) 1)) "")
(if (vl-position ch pat) ; number
(setq maxlen (1+ maxlen))
(setq count (max count maxlen) maxlen 0)
)
)
(setq count (max count maxlen)) ;_<<< ADD 21.06.2007 by VVA
)
Lst
)
count
)
;;===============================================
(setq count (GetCount ListOfString)
NorStrs (mapcar '(lambda (x) (NormalizeNumberInString x count))
ListOfString)
)
(and IgnoreCase (setq NorStrs (mapcar 'strcase NorStrs)))
(mapcar '(lambda (x) (nth x ListOfString)) (vl-sort-i NorStrs '<))
) ;_ end of defun
Hi,I have this:
Could anyone help me to sort this way?
("AS1" "AS2" "AS10" "T1" "T2" "T10" "T1A" "T2A" "T10A" "T1B" "T2B" T10B ")
Thanks in advance.
; Function: ALE_List_SortAtoms
;
; Version 1.00 - 01/2005 (old name ALE_SortAlphaNum)
; Version 1.13 - 24/01/2007
; Version 1.20 - 26/03/2007
; Version 1.21 - 26/08/2010
;
; Example:
; (ALE_List_SortAtoms
; '("C20.10R" "C20.3R" nil (1 . 20) "C12" nil "C20.1R" "0"
; "20K" T (10 20 30) T "2K" -99 "C2" 0 (55) "C201" "-99"
; "L4" "L1" "L100" "-200K" 8 1 "2C" "20C.1R" "20C.10R"
; "20C.3R" "20C.R4" "20C.R44" "20C.R3" 4 "20C" "4R" "4C"
; 3.2 1 10 100 200 2 20
; )
; )
; =>(nil nil -99 0 1 1 2 3.2 4 8 10 20 100 200 "-200K" "-99" "0"
; "2C" "2K" "4C" "4R" "20C" "20C.10R" "20C.1R" "20C.3R" "20C.R3"
; "20C.R4" "20C.R44" "20K" "C2" "C12" "C20.10R" "C20.1R" "C20.3R"
; "C201" "L1" "L4" "L100" T T (55) (10 20 30) (1 . 20)
; )
;
(defun ALE_List_SortAtoms (InpLst)
(mapcar
'(lambda (LmbDat) (nth LmbDat InpLst))
(vl-sort-i InpLst
'(lambda (LmbDt1 LmbDt2 / Typ001 Typ002 Num001 Num002 Flg001 Flg002)
(setq Typ001 (type LmbDt1) Typ002 (type LmbDt2))
(cond
( (not LmbDt1) )
( (not LmbDt2) nil)
( (eq Typ001 'LIST) nil)
( (eq Typ002 'LIST) )
( (eq Typ001 'SYM) nil)
( (eq Typ002 'SYM) )
( (and
(setq Flg001 (numberp LmbDt1) Flg002 (numberp LmbDt2))
Flg001
)
(< LmbDt1 LmbDt2)
)
( (and Flg002 (not Flg001)) nil )
( Flg001 )
( (=
(setq Num001 (if Flg001 LmbDt1 (atof LmbDt1)))
(setq Num002 (if Flg002 LmbDt2 (atof LmbDt2)))
0
)
(setq
Num001 (atof
(vl-string-translate
" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"000000000000000000000000000"
(strcase LmbDt1)
)
)
Num002 (atof
(vl-string-translate
" ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"000000000000000000000000000"
(strcase LmbDt2)
)
)
LmbDt1 (vl-string-translate "123456789" "000000000" LmbDt1)
LmbDt2 (vl-string-translate "123456789" "000000000" LmbDt2)
)
(cond
( (and (= LmbDt1 LmbDt2) (< Num001 Num002)) )
( (< LmbDt1 LmbDt2) )
)
)
( (and (zerop Num001) (not (eq LmbDt1 "0"))) nil )
( (and (zerop Num002) (not (eq LmbDt2 "0"))) )
( (or (< Num001 Num002) (and (= Num001 Num002) (< LmbDt1 LmbDt2))) )
)
)
)
)
)
(ALE_List_SortAtoms '("T1A" "AS2" "AS10" "T10B" "T1" "AS1" "T2" "T10" "T2A" "T10A" "T1B" "T2B"))
=====> ("AS1" "AS2" "AS10" "T1" "T2" "T10" "T10A" "T10B" "T1A" "T2A" "T1B" "T2B")
Your=> ("AS1" "AS2" "AS10" "T1" "T2" "T10" "T1A" "T2A" "T10A" "T1B" "T2B" "T10B")
You might look into DOSLib's DOS_STRSORT function and it's logical sorting option.
http://www.en.na.mcneel.com/doslib/string_functions/dos_strsort.htm
For example:
Command: (dos_strsort '("A1" "A10" "A9" "B05" "B11" "B2") -1)
("A1" "A9" "A10" "B2" "B05" "B11")
Does this help?
-- Dale
I have this:Code: [Select](ALE_List_SortAtoms '("T1A" "AS2" "AS10" "T10B" "T1" "AS1" "T2" "T10" "T2A" "T10A" "T1B" "T2B"))
=====> ("AS1" "AS2" "AS10" "T1" "T2" "T10" "T10A" "T10B" "T1A" "T2A" "T1B" "T2B")
Your=> ("AS1" "AS2" "AS10" "T1" "T2" "T10" "T1A" "T2A" "T10A" "T1B" "T2B" "T10B")
I have this in my library:...Hi Lee,
ALE=====> ("AS1" "AS2" "AS10" "T1" "T2" "T10" "T10A" "T10B" "T1A" "T2A" "T1B" "T2B")
LM:=====> ("AS1" "AS2" "AS10" "T1" "T1A" "T1B" "T2" "T2A" "T2B" "T10" "T10A" "T10B")
Antistar> ("AS1" "AS2" "AS10" "T1" "T2" "T10" "T1A" "T2A" "T10A" "T1B" "T2B" "T10B")
which is more correct?
I have this in my library:Code - Auto/Visual Lisp: [Select]
;; Alphanumerical Sort - Lee Mac ;; Sorts a list of strings containing a combination of alphabetical & numerical characters. (and (= x y) ) ) ) (cond ( (< x y)) ) ) ) ) ) ) ;; Split String - Lee Mac ;; Splits a string into a list of text and numbers ( (read (vl-list->string (cond ( (= 92 b) ) ) ) ) ) ) ) ) ) ")" ) ) ) ) )
What if I have a multi dimension list like this:
(("A.05" "12.34" "Regular") ("A.10 "34.54 "BigSize") ("B.9" "66.73" "Regular") ("A.05" "12.55" "BigSize"))
What is the most efficient and correct way to sort this list?
What if I have a multi dimension list like this:
(("A.05" "12.34" "Regular") ("A.10 "34.54 "BigSize") ("B.9" "66.73" "Regular") ("A.05" "12.55" "BigSize"))
What is the most efficient and correct way to sort this list?
Should the list be sorted by the first element; or by first, then second, then third?
I gave a wrong list. It should be like this:Code: [Select](("A.05" 12.34 "Regular") ("A.10" 34.54 "BigSize") ("B.9" 66.73 "Regular") ("A.10" 12.12 "BigSize") ("A.05" 12.55 "BigSize"))
The result:Code: [Select](("A.05" 12.34 "Regular") ("A.05" 12.55 "BigSize") ("A.10" 12.12 "BigSize") ("A.10" 34.54 "BigSize") ("B.9" 66.73 "Regular"))
The list should be sort by the first element and then second.
I'm sure this logic is flawed and horribly inefficient but it's the first thing that came to mind :)
DOH! :-) That's some strange numbering since "A.05" is formatted correctly.I'm sure this logic is flawed and horribly inefficient but it's the first thing that came to mind :)
Add ("B.10" 66.73 "Regular") to your list :wink:
DOH! :-) That's some strange numbering since "A.05" is formatted correctly.I'm sure this logic is flawed and horribly inefficient but it's the first thing that came to mind :)
Add ("B.10" 66.73 "Regular") to your list :wink:
Consider the following function based on the code from my earlier post -Code - Auto/Visual Lisp: [Select]
Example:Code - Auto/Visual Lisp: [Select]
_$ (mysort '(("A.05" 12.34 "Regular") ("A.10" 34.54 "BigSize") ("B.9" 66.73 "Regular") ("A.10" 12.12 "BigSize") ("A.05" 12.55 "BigSize"))) (("A.05" 12.34 "Regular") ("A.05" 12.55 "BigSize") ("A.10" 12.12 "BigSize") ("A.10" 34.54 "BigSize") ("B.9" 66.73 "Regular"))