Strip part of string

Discussion in 'AutoCAD' started by Dave M, Nov 16, 2004.

  1. Dave M

    Dave M Guest

    I have some code that places a block on a drawing based on a valid border
    that was selected. Currently, I have our standard borders hard coded into
    the routine, but I would like to modify the boder names so that as long as
    the border name ends in "24x36" or "30x42" it will work. I basically would
    like to look only at the last 5 characters of the border selected, not the
    entire name.

    Current Code:

    (if (or (= bdrname "B-24x36")(= bdrname "B-30x42")(= bdrname
    "Client1-24x36")(= bdrname "Client2-30x42") etc...

    I would like to just look to see if the last 5 characters are "24x36" or
    "30x42" and have the code work for all of them.

    Thanks in advance for any help

    Dave
     
    Dave M, Nov 16, 2004
    #1
  2. You could try something like:

    (defun c:qq ()

    (setq bdrname "aaa24x36")
    (if (> (strlen bdrname) 4)
    (progn
    (setq temp1 (substr bdrname (- (strlen bdrname) 4)))
    (if (= temp1 "24x36")
    (progn
    (print "passed")
    (print temp1)
    )
    (progn
    (print "didn't pass")
    (print temp1)
    )
    )
    )
    )
    )
     
    Martin Shoemaker, Nov 16, 2004
    #2
  3. Dave M

    Tom Smith Guest

    Luis' wcmatch solution is the cleanest, assuming you want a true result for
    both cases. If you needed to distinguish between them, I'd use two wcmatch
    tests rather than going through the substr processing.
     
    Tom Smith, Nov 16, 2004
    #3
  4. You might also want to make sure to check for upper case..
    (wcmatch (strcase YourValue) "*24X36")
     
    Alan Henderson @ A'cad Solutions, Nov 16, 2004
    #4
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.