Checking the textmask of two strings

Discussion in 'AutoCAD' started by Marcel Janmaat, Jan 25, 2005.

  1. For example;

    Whe use projectnumbers like these "1234", "1234-01", "1234-1W12",
    "1234-01W12", "1234-01W123" or "1234W1"

    The firts four characters represent the basic projectnumber and are always
    numbers. (ascii between 48 and 57)

    Optional in this order it can be folowed by;
    The "-" followed by a number represents a project-part
    and the "W" follwed by a number represents a change to a project or
    projectpart

    Not like this: "1234W12-01"

    I want to check the mask of this projectnumber against eny other type of
    string to notify the user the wrong textmask is being used.

    Has anyone got some sugestions on how to approach this?
    I know the difficulty is in in the "-" en "W" folowed by one or more numbers
    being optional an wich can varry.

    Regards M
     
    Marcel Janmaat, Jan 25, 2005
    #1
  2. Marcel Janmaat

    cwitt Guest

    the wrong mask?..

    are you refering to the mask size (relative to the text string)?
     
    cwitt, Jan 25, 2005
    #2
  3. Marcel Janmaat

    MP Guest

    I think he means "mask" as the extra characters which can be added to the
    basic project number string. not an autocad "textmask"
    just a guess.
    Mark
     
    MP, Jan 25, 2005
    #3
  4. Marcel Janmaat

    Jürg Menzi Guest

    Hi Marcel

    Maybe this can do the job:
    Code:
    (defun Test (Prj / FstPrt NxtPrt TmpLst)
    (if (not (wcmatch (substr Prj 1 4) "*[~0-9]*"))
    (progn
    (setq TmpLst (MeString2List (substr Prj 5) "W")
    FstPrt (car TmpLst)
    NxtPrt (cadr TmpLst)
    )
    (cond
    ((not TmpLst))
    ((and NxtPrt (wcmatch NxtPrt "*[~0-9]*") nil))
    ((or (/= (substr FstPrt 1 1) "-") (wcmatch FstPrt "*[~0-9-]*")) nil)
    (T)
    )
    )
    )
    )
    
    (defun MeString2List (Stg Del / StrPos TmpLst TmpStr)
    (setq TmpStr Stg
    StrPos (vl-string-search Del TmpStr)
    )
    (while StrPos
    (setq TmpLst (cons (substr TmpStr 1 StrPos) TmpLst)
    TmpStr (substr TmpStr (+ StrPos 2))
    StrPos (vl-string-search Del TmpStr)
    )
    )
    (if (> (strlen TmpStr) 0)
    (setq TmpLst (cons TmpStr TmpLst))
    )
    (reverse TmpLst)
    )
    
    Cheers
     
    Jürg Menzi, Jan 25, 2005
    #4
  5. Thanks Jürg, I think I'll use this. It acts almost like I want to work.

    I noticed that (test "1234-W12000") also came out with T, wich it shouldn't.

    After the "-" or "W" the number of charcters may varry from 1 to 3 and must
    be numbers.
    For example: "1234-1W120" or "1234-10W1" or "1234-101W12"

    Thanks again for helping me on the subject!

    M.Janmaat.
    The Netherlands.
     
    Marcel Janmaat, Jan 26, 2005
    #5
  6. Shouldn't this ((and NxtPrt (wcmatch NxtPrt "*[~0-9]*") nil)) be like
    this...

    ((and NxtPrt (wcmatch NxtPrt "*[~0-9]*")) nil)

    ?
     
    Marcel Janmaat, Jan 26, 2005
    #6
  7. Marcel Janmaat

    Jürg Menzi Guest

    Hi Marcel

    Glad to help you...¦-)
    In this case you've to add a strlen check:
    Code:
    (cond
    ((not TmpLst))
    ((and NxtPrt (or (> (strlen NxtPrt) 3) (wcmatch NxtPrt "*[~0-9]*"))) nil)
    ((or
    (/= (substr FstPrt 1 1) "-")
    (> (strlen FstPrt) 4)
    (wcmatch FstPrt "*[~0-9-]*")
    )
    nil
    )
    (T)
    )
    
    Cheers
     
    Jürg Menzi, Jan 26, 2005
    #7
  8. Marcel Janmaat

    Jürg Menzi Guest

    Sorry, typo...

    Cheers
     
    Jürg Menzi, Jan 26, 2005
    #8
  9. Thanks Juerg,

    I still havn't got it right yet.

    Here are some test results from probable right project numbers;

    _$ (foreach pnr '("1234" "1234-01" "1234-1W12" "1234-01W12" "1234-01W123"
    "1234W1") (princ (pnr_chk pnr)))
    TTTTTnilnil

    "1234W1" returns nil wich should be T

    Here are some test results from probable wrong project numbers;

    _$ (foreach pnr '("1234-" "123401" "1234-W12" "123401-1W12" "1234-01-W123"
    "1234W1w13" "1234-W113") (princ (pnr_chk pnr)))
    TnilTnilTnilTT

    "1234-", "1234-W12", "1234-01-W123" and "1234-W113" return T wich should be
    nil

    Unfortunately the positions are not fixed (like the first four characters).
    Then it would be a lot easier.

    Cheers M

    _$
     
    Marcel Janmaat, Jan 26, 2005
    #9
  10. Now i solved it like this;

    (defun asg_pnr ( pnr / pnr pos dl2 dl3 err )

    ;(setq err nil) (setq pnr "123401-1W12")

    (setq tmp pnr)

    (if (wcmatch (substr tmp 1 4) "*[~0-9]*")
    (setq tmp nil) ; bij geen nummerieke waarde
    (progn (setq dl2 (substr tmp 5) tmp (substr tmp 1 4))
    (if (if (setq pos (vl-string-search "-" dl2)) (setq dl2 (substr dl2 (+
    pos 2))))
    (if (setq pos (vl-string-search "W" dl2)) (setq dl3 (substr dl2 (+
    pos 2)) dl2 (substr dl2 1 pos)) (setq dl2 (substr dl2 1 pos)))
    (if (setq pos (vl-string-search "W" dl2)) (setq dl3 (substr dl2 (+
    pos 2))))
    )
    (if (and dl2 (/= dl2 "") (null (wcmatch dl2 "*[~0-9]*"))) (setq tmp
    (strcat tmp "-" dl2)))
    (if (and dl3 (/= dl3 "") (null (wcmatch dl3 "*[~0-9]*"))) (setq tmp
    (strcat tmp "W" dl3)))
    )
    )

    (if (equal tmp pnr) pnr)

    )

    If you see any posible failures please let me know!

    Thanks for the help!
     
    Marcel Janmaat, Jan 26, 2005
    #10
  11. Marcel Janmaat

    Jürg Menzi Guest

    Hi Marcel

    Your solution seems to work but is not clearly arranged (like my first
    solution)...¦-) My second proposition is to use patterns:
    Code:
    (defun asg_pnr (pnr)
    (cond
    ((wcmatch pnr "####"))
    ((wcmatch pnr "####W#"))
    ((wcmatch pnr "####W##"))
    ((wcmatch pnr "####W###"))
    ((wcmatch pnr "####-#"))
    ((wcmatch pnr "####-##"))
    ((wcmatch pnr "####-###"))
    ((wcmatch pnr "####-#W#"))
    ((wcmatch pnr "####-#W##"))
    ((wcmatch pnr "####-#W###"))
    ((wcmatch pnr "####-##W#"))
    ((wcmatch pnr "####-##W##"))
    ((wcmatch pnr "####-##W###"))
    ((wcmatch pnr "####-###W#"))
    ((wcmatch pnr "####-###W##"))
    ((wcmatch pnr "####-###W###"))
    (T nil)
    )
    )
    
    This allows easier maintenance of the code.

    Cheers
     
    Jürg Menzi, Jan 26, 2005
    #11
  12. Yes!
    I guess this is even better. And a lot more simple!
    Thanks again.

    Cheers M
     
    Marcel Janmaat, Jan 27, 2005
    #12
  13. Marcel Janmaat

    Jürg Menzi Guest

    Hi Marcel

    Glad to help you...¦-)

    Groeten aan Nederland
     
    Jürg Menzi, Jan 27, 2005
    #13
  14. Funny,

    Are those the only Dutch words you know or might we've had this conversation
    in Dutch?

    Grussen an Switzerland. : )
     
    Marcel Janmaat, Jan 27, 2005
    #14
  15. Marcel Janmaat

    Jürg Menzi Guest

    Hi Marcel

    I've been visiting the netherlands several times, first in 1972, last in 2003.
    Friends of me live there (Ouderkerk near Amsterdam).
    I'm able to follow a conversation (Dutch has a lot of similarities to the
    swiss german dialect). In case of writing, my knowledge is not enough.
    So I prefer english communication in the newsgroup, also to avoid excluding
    other participants from the discussion.

    Cheers
     
    Jürg Menzi, Jan 27, 2005
    #15
  16. Hi Menzi,

    I prefer english aswell.

    M.Janmaat
    System administrator
    Hiensch Engineering B.V.
    Badhoevedorp, the Netherlands (also near Amsterdam)
    www.hiensch.nl
     
    Marcel Janmaat, Jan 27, 2005
    #16
  17. Thanks for the effort Herman, but isn't Juerg's approach a lot more simple?

    (defun asg_pnr (pnr)
    (cond
    ((wcmatch pnr "####"))
    ((wcmatch pnr "####W#"))
    ((wcmatch pnr "####W##"))
    ((wcmatch pnr "####W###"))
    ((wcmatch pnr "####-#"))
    ((wcmatch pnr "####-##"))
    ((wcmatch pnr "####-###"))
    ((wcmatch pnr "####-#W#"))
    ((wcmatch pnr "####-#W##"))
    ((wcmatch pnr "####-#W###"))
    ((wcmatch pnr "####-##W#"))
    ((wcmatch pnr "####-##W##"))
    ((wcmatch pnr "####-##W###"))
    ((wcmatch pnr "####-###W#"))
    ((wcmatch pnr "####-###W##"))
    ((wcmatch pnr "####-###W###"))
    (T nil)
    )
    )
     
    Marcel Janmaat, Jan 27, 2005
    #17
  18. Thanx for the input Herman.It's being appreciated. I'm always interested in
    someone els's ideas.
    For the same reasons you have...

    If you look at the code you've written and what I wrote earlier, and then
    look at wat Juerg wrote,
    then I think were sometimes making things too dificult for ourselves. I
    think Juerg's code instantly makes it clear what the code is about.

    Cheers : )

    M
     
    Marcel Janmaat, Jan 28, 2005
    #18
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.