wcmatch the answer?

Discussion in 'AutoCAD' started by BillZ, May 6, 2004.

  1. BillZ

    BillZ Guest

    R2005 Vlisp:

    I have a string number "32456" and I want to know if it matches some string numbers in a list that have an extra character at the end of the string or not. The list looks like:
    ("37646" "32456A" 31442" 32456B" "32456" "34567" "34555C")
    If "32456" matches the first 5 characters of "32456A" or "32456B" and matches "32456" I need to know that there are 3 instances of that number in the list.

    TIA

    Bill
     
    BillZ, May 6, 2004
    #1
  2. Hi Bill,

    (setq i 0)
    (foreach x '("37646" "32456A" "31442" "32456B" "32456" "34567" "34555C")
    (if (wcmatch x "32456*")
    (setq i (1+ i)) )
    )
    i

    Maybe I am missing something?



    --

    Autodesk Discussion Group Facilitator


    list that have an extra character at the end of the string or not. The list looks like:
    need to know that there are 3 instances of that number in the list.
     
    Jason Piercey, May 6, 2004
    #2
  3. BillZ

    BillZ Guest

    (setq i 0)
    (if (wcmatch x "32456*")
    (setq i (1+ i)) )
    )
    i

    Maybe I am missing something?

    Jason,
    This is fine and will work like I need it to.

    But now I found a new problem.
    Part_string was coming: "32969 35077 35300 50929 52745 53274 53282 63906 63907 64162 66180 70049 77502"
    So all I had to do to turn it into a list was:

    (setq part_list (read (strcat "(" part_string ")")))

    Now I see that some of the guys have input the string with commas.
    "32969,35077,35300,50929,52745,53274,53282,63906,63907,64162,66180,70049,77502"

    So how do I turn this into a list of part numbers?

    Bill
     
    BillZ, May 6, 2004
    #3
  4. BillZ

    Doug Broad Guest

    Look into vl-string-translate.


     
    Doug Broad, May 6, 2004
    #4
  5. Do you have a parse function? Picked this one up
    from acadx.com (IIRC).

    ; creates multiple strings from a single string
    ; - string, string to breakdown
    ; [d] - string, separator
    ; return: list of strings
    (defun parse (s d / i l tmp rtn)
    (cond
    ((/= "" d)
    (setq l (strlen d))
    (while (setq i (vl-string-search d s))
    (setq tmp (substr s 1 i))
    (setq rtn (cons tmp rtn))
    (setq s (substr s (1+ (+ l (strlen tmp))) (strlen s)))
    )
    (vl-remove "" (reverse (cons s rtn)))
    )
    (t s)
    )
    )
     
    Jason Piercey, May 6, 2004
    #5
  6. ; delimiter = 1 character
    ;
    (defun ALE_String2List (InpStr CarDlm / SttPos EndPos TmpLst)
    (setq
    CarDlm (ascii CarDlm) SttPos 0
    EndPos (vl-string-position CarDlm InpStr)
    )
    (while EndPos
    (setq
    TmpLst (cons (substr InpStr (1+ SttPos) (- EndPos SttPos)) TmpLst)
    SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos)
    )
    )
    (reverse (cons (substr InpStr (1+ SttPos)) TmpLst))
    )

    or

    ;John Uhden, Cadlantic/formerly CADvantage
    ; delimiter = 1 or more character
    ;
    (defun Str2List (str pat / i j n lst)
    (cond
    ((/= (type str)(type pat) 'STR))
    ((= str pat)'(""))
    (T
    (setq i 0 n (strlen pat))
    (while (setq j (vl-string-search pat str i))
    (setq lst (cons (substr str (1+ i)(- j i)) lst)
    i (+ j n)
    )
    )
    (reverse (cons (substr str (1+ i)) lst))
    )
    )
    )
    --
    ________________________________________________

    Marc'Antonio Alessi
    http://xoomer.virgilio.it/alessi
    (strcat "NOT a " (substr (ver) 8 4) " guru.")

    O.S. = XP Pro 2002 Ita - Sp.1
    AutoCAD = 2004 Ita - Sp.1a
    ________________________________________________
     
    Marc'Antonio Alessi, May 6, 2004
    #6
  7. BillZ

    BillZ Guest

    Look into vl-string-translate.
    <<

    Doug,
    Sorry I should have said I am nursing some R14 Vanilla lisp here.
    That would make it so much easier.

    Thanks

    Bill
     
    BillZ, May 6, 2004
    #7
  8. BillZ

    Jürg Menzi Guest

    Bill

    Should work on your sweets LISP...
    ;
    ; == Function String2List
    ; Converts a string to a list.
    ; Arguments [Type]:
    ; Stg = String [STR]
    ; Del = Delimiter [STR]
    ; Return [Type]:
    ; > Converted string

    • ; Notes:
      ; None
      ;
      (defun String2List (stg cha / countr curchr tmplst tmpstr)
      (setq countr 1
      tmplst '()
      tmpstr ""
      )
      (repeat (1+ (strlen stg))
      (setq curchr (substr stg countr 1))
      (if (or (= curchr "") (= curchr cha))
      (setq tmplst (cons tmpstr tmplst)
      tmpstr ""
      )
      (setq tmpstr (strcat tmpstr curchr))
      )
      (setq countr (1+ countr))
      )
      (reverse tmplst)
      )

      Cheers
     
    Jürg Menzi, May 6, 2004
    #8
  9. BillZ

    John Uhden Guest

    Hi, Marco. That exercise was a lot of fun. My code still credits you for your
    contributions. Recently, I found the multiple-character delimiter to be most
    helpful with a string of text that was formatted to force new lines by "\r\n."
    The footnote reads ";; It's not as fast as Marc'Antonio's, but pretty close."
     
    John Uhden, May 7, 2004
    #9
  10. BillZ

    PG. Guest

    (setq partstr
    "32969,35077,35300,50929,52745,53274,53282,63906,63907,64162,66180,70049,775
    02")
    (setq partlst "(")
    (setq count 1)
    (repeat (strlen partstr)
    (setq char1 (substr partstr count 1))
    (if (= char1 ",")
    (setq char1 " "))
    (setq partlst (strcat partlst char1))
    (setq count (1+ count))
    )
    (setq partlst (strcat partlst ")"))
    (setq partlst (read partlst))
     
    PG., May 7, 2004
    #10
  11. Hi John, thanks for credits ;)

    I agree:

    ; John Uhden & Marc'Antonio Alessi
    ; delimiter = 1 or more characters - no input check
    ;
    (defun ALE_String2ListStrDlm (InpStr StrDlm / SttPos TmpPos DlmLng TmpLst)
    ; (cond
    ; ( (/= (type InpStr) (type StrDlm) 'STR) )
    ; ( (= InpStr StrDlm) '("") )
    ; (T
    (setq
    DlmLng (strlen StrDlm) SttPos 0
    TmpPos (vl-string-search StrDlm InpStr SttPos)
    )
    (while TmpPos
    (setq
    TmpLst (cons (substr InpStr (1+ SttPos) (- TmpPos SttPos)) TmpLst)
    SttPos (+ TmpPos DlmLng)
    TmpPos (vl-string-search StrDlm InpStr SttPos)
    )
    )
    (reverse (cons (substr InpStr (1+ SttPos)) TmpLst))
    ; )
    ; )
    )

    ; InpStr = "1\t\t43\t\tPresident\tGeorge W. Bush\t1600 etc."
    ; StrDlm = "\t"

    ; simple tests:
    ; ALE_STRING2LIST > 100000 iterations: 5.83 secs.
    ; ALE_STRING2LISTSTRDLM > 100000 iterations: 6.29 secs.

    Cheers.

    Marco

    --
    ________________________________________________

    Marc'Antonio Alessi
    http://xoomer.virgilio.it/alessi
    (strcat "NOT a " (substr (ver) 8 4) " guru.")

    O.S. = XP Pro 2002 Ita - Sp.1
    AutoCAD = 2004 Ita - Sp.1a
    ________________________________________________
     
    Marc'Antonio Alessi, May 8, 2004
    #11
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.