Wildcard In String

Discussion in 'AutoCAD' started by David Bethel, Jan 22, 2004.

  1. David Bethel

    David Bethel Guest

    Anyone know of a simple wcmatch test to see if a string contains a
    wildcard character as in a block name pattern search?

    So far I have:

    (while (or (not bn)
    (not (or (snvalid bn)
    (wcmatch bn [ "#" "@" "." "*" "?" "~" "[" ]))))
    (setq bn (getstring "\nBlock Name Pattern: ")))

    -David
     
    David Bethel, Jan 22, 2004
    #1
  2. Hi David,

    Didn't test this much, but how about....

    ; function to determine if a string
    ; contains any wildcard characters.
    (defun wcmatchChr (string)
    (wcmatch string "*[#@.*?~]*")
    )

    (wcmatchChr "a#bc") -> T
    (wcmatchChr "a*bc") -> T
    (wcmatchChr "a?bc") -> T
    (wcmatchChr "abc") -> nil

    ?
     
    Jason Piercey, Jan 22, 2004
    #2
  3. David Bethel

    David Bethel Guest

    Thanks

    I did have to add a back quote for commas ????

    (wcmatch string "*[#@.`,*?~]*")

    -David
     
    David Bethel, Jan 22, 2004
    #3
  4. David Bethel

    David Bethel Guest

    Didn't work that way

    R12 -David
     
    David Bethel, Jan 22, 2004
    #4
  5. Shouldn't have to escape the comma...

    <snip>
    All characters enclosed in brackets ([ . . . ]) are read
    literally, so there is no need to escape them, with the
    following exceptions: the tilde character (~) ........
    <snip>
     
    Jason Piercey, Jan 22, 2004
    #5
  6. Hmmm.... 2002

    (setq string "a,b")
    "a,b"

    (wcmatch string "*[#@.*?~],*")
    T
     
    Jason Piercey, Jan 22, 2004
    #6
  7. oops! misplaced comma..... You are correct

    (setq string "a,b")
    "a,b"

    (wcmatch string "*[#@.*?~,]*")
    nil

    (wcmatch string "*[#@.*?~`,]*")
    T


    --

    -Jason
    Member of the Autodesk Discussion Forum Moderator Program


     
    Jason Piercey, Jan 22, 2004
    #7
  8. David Bethel

    John Uhden Guest

    Here's an old one...
    ;;--------------------------------------------------
    ;; Function to turn a string into a literal string:
    ;;
    (defun @literal (str / new ch i n)
    (setq i 1
    n (strlen str)
    new ""
    )
    (while (<= i n)
    (setq new (strcat new "`" (substr str i 1))
    i (1+ i)
    )
    )
    new
    )
     
    John Uhden, Jan 23, 2004
    #8
  9. David Bethel

    David Bethel Guest

    John,

    You lost me on that 1 ???? -David
     
    David Bethel, Jan 23, 2004
    #9
  10. David Bethel

    John Uhden Guest

    I have a program where the user enters his own custom description prefixes and
    suffixes that can contain any characters, so you have to read them literally...

    Command: (setq str "320.01.#" prefix "320.01" suffix ".#")
    ".#"
    Command: (wcmatch str (strcat prefix "*" suffix))
    nil
    Command: (wcmatch str (strcat (@literal prefix) "*" (@literal suffix)))
    T

    So you say "why don't you just test for equality?"
    Because there might be other characters in the string between the prefix and
    suffix that are permitted...
    Command: (setq str "320.01A.#")
    "320.01A.#"
    Command: (wcmatch str (strcat (@literal prefix) "*" (@literal suffix)))
    T
     
    John Uhden, Jan 24, 2004
    #10
  11. David Bethel

    David Bethel Guest

    Oh. I see -David
     
    David Bethel, Jan 24, 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.