shorting list..

Discussion in 'AutoCAD' started by caduser, Jul 5, 2003.

  1. caduser

    caduser Guest

    '("A3" "A11" "A5" "A1") can shorting? and how the lisp look like
     
    caduser, Jul 5, 2003
    #1
  2. caduser

    Kevin Nehls Guest

    (acad_strlsort '("A3" "A11" "A5" "A1"))

    ("A1" "A11" "A3" "A5")

    Also hit the VLIDE help file and search for "list manipulation
    functions" and vl-sort

    HTH
    Kevin
     
    Kevin Nehls, Jul 5, 2003
    #2
  3. caduser

    caduser Guest

    i need like this ("A1" "A3" "A5" "A11") it's can?
     
    caduser, Jul 5, 2003
    #3
  4. caduser

    Mark Propst Guest

    is it always only A's (only one prefix letter)???
    never ("A1" "A2" "A3" "B1" "B2" "B3")???
    if it is always A, then it's simple, but if not, it's more involved
    (defun alphaNumsort (strlist)
    (print strlist)
    (mapcar
    (function
    (lambda(st st2)
    (strcat (substr st 1 1)(itoa st2))
    )
    );f
    strlist
    (vl-sort
    (mapcar
    (function
    (lambda(s)
    (atoi (substr s 2))
    )
    )
    strlist)
    '<
    )

    );m
    );d
    (defun test()
    (setq testlst(list "A2" "A3" "A45" "A1" "A5" "A7" "A100" "A6" "A1000"))
    (alphaNumsort testlst)
    )

    _$ (test)

    ("A2" "A3" "A45" "A1" "A5" "A7" "A100" "A6" "A1000")
    ("A1" "A2" "A3" "A5" "A6" "A7" "A45" "A100" "A1000")


    but that *won't* work if you have
    ;(setq testlst(list "A3" "B4" "A5" "B1" "A1"))
     
    Mark Propst, Jul 5, 2003
    #4
  5. caduser

    jonesr Guest

    Pad with leading zeros ???
    "A03" "A11" "A05" "A01"
    "A003" "A011" "A005" "A001"
     
    jonesr, Jul 6, 2003
    #5
  6. caduser

    caduser Guest

    in testlsp i add same more "B34" "B2" "B12" "C12" "C4" "C2" and so on....
    but the adds element is not display
     
    caduser, Jul 7, 2003
    #6
  7. caduser

    Mark Propst Guest

    That's why I told you it wouldn't work with those cases, you'll have to
    write differently if you don't only have a's. your example only had a's.
    Like I said, if you have more than one prefix letter this will not work, but
    you might be able to figure out how to get it to work with the other letters
    by seeing how this works
    hint vl-sort is the culprit cause it *sometimes* discards duplicate values
    so you have to sort yours a's and b's and c's separately, get it?
     
    Mark Propst, Jul 7, 2003
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.