Lisp Question regarding obtaining parts of a String

Discussion in 'AutoCAD' started by Mr. B, Feb 25, 2006.

  1. Mr. B

    Mr. B Guest

    If you have a string of text in a Variable STRNG = MyTestString

    and (substr STRNG 7) returns 'String'

    ..... how can I get 'MyTest' from STRNG.

    I'll proably smack myself if I get an answer. But I can't find any function
    that will do this.

    Thanks in Advance!

    BruceF
     
    Mr. B, Feb 25, 2006
    #1
  2. Mr. B

    argusy Guest

    substr STRNG 0,6 ?
    (starting from zero, six characters)
    Argusy
     
    argusy, Feb 25, 2006
    #2
  3. Mr. B

    Mr. B Guest

    That doesn't work (at least for me). I don't want the end part of the string.
    But the begining part (ie: reverse search). I want to get a number of
    characters starting from the END of the string going backwards.

    Regards,

    BruceF
     
    Mr. B, Feb 25, 2006
    #3
  4. Mr. B

    Mr. B Guest

    Forget it... you are Correct (somewhat). Do NOT use a Zero or a Comma. So
    your example should read:
    substr STRNG 1 6

    Then it wll work!!! Thanks!

    I've an old Autocad Lisp book from R12 time. Doesn't show that :(

    Regards,

    BruceF
     
    Mr. B, Feb 25, 2006
    #4
  5. Mr. B

    Happy Trails Guest

    Does this mean you'll be updating that RenLyr lisp to replace strings
    anywhere, not just at the front?

    Happy Trails To You
     
    Happy Trails, Feb 25, 2006
    #5
  6. Mr. B

    argusy Guest

    I should have known not to put in the comma.
    I've just been in the visual basic ngs, and the VB equivalent is
    substr(stringtosearch,searchstring,start,numberofchars)
    BUT VB's start is zero, so I made a quick assumption that your post required the
    same.
    I should have counted the number of characters to the start of "STRING"
    That would have told me Lisp would have started at 1

    Argusy
     
    argusy, Feb 25, 2006
    #6
  7. Mr. B

    Brian Salt Guest

    Just to butt in, The R12 AutoLisp Programmers Reference book shows it on
    page 158. Perhaps you have some other book?

    Brian.
     
    Brian Salt, Feb 25, 2006
    #7
  8. Mr. B

    argusy Guest

    Butt in any time, Brian
    Argusy

     
    argusy, Feb 25, 2006
    #8
  9. Mr. B

    Mr. B Guest

    NP... butt in away.

    My R12 book (dated May 11, 1992, publication 100191-01) has SubStr on page
    155. I guess I've just have never used it before in the way I needed it now.

    P158 has TblSearch, Terpri and TextBox on it (my book that is).

    Regards,

    BruceF
     
    Mr. B, Feb 25, 2006
    #9
  10. Mr. B

    Mr. B Guest

    I hear you. I also program in VB.net and VB6 and I too get confused/forgetful
    sometimes on the syntax. :)

    Regards,

    BruceF
     
    Mr. B, Feb 25, 2006
    #10
  11. Mr. B

    Brian Salt Guest

    Ha! Somebody added a couple of pages between May and June 1992, I guess.

    Just one month and already modified. Must have been important :)-)

    Brian.
     
    Brian Salt, Feb 25, 2006
    #11
  12. Mr. B

    Mr. B Guest

    Interesting... Just imagine, back in the good old Daze, we use to get books!!!
    Actually they were a royal pain in the A** when you ended up with 10 or more
    copies of every firgging thing! Times have changed!

    Regards,

    BruceF
     
    Mr. B, Feb 25, 2006
    #12
  13. Mr. B

    Mr. B Guest

    No :)

    I think that would be a bit harder. You'd have to somehow figure out how many
    characters into the Existing String, etc.

    I originally wrote that simply because people were Inserting Xrefs into their
    drawings. And also because of some MAC Cadd files I'd get (exported). So I
    wanted something to clear out the beginning crap of layers (same thing with
    Blocks).

    So I never intended it to be a search replace string kind of thing.

    It would probably not be too much of a hassle if I had the Code to do a proper
    search of a string in a Layer name.

    Regards,

    BruceF
     
    Mr. B, Feb 25, 2006
    #13
  14. Mr. B

    Brian Salt Guest

    :)_(( Indeed they have.
     
    Brian Salt, Feb 25, 2006
    #14
  15. Mr. B

    Happy Trails Guest

    Thanks, Kitty, but the dwg I'm working with at the moment has some
    names that start with "TTL-0$" that is a leftover from an xref and a
    partial string replace from Mr. B's lsp. It seems both of these layer
    rename functions choke up on trying to find/replace a string that has
    a dollar sign (I think) at the end. It seems kind of stupid since it
    was acad that put those dollar signs in there.

    It is probably something really anal in lisp like you just cannot end
    a string with a dollar sign, or something equally dopey.




    Happy Trails To You
     
    Happy Trails, Feb 26, 2006
    #15
  16. Mr. B

    Happy Trails Guest

    Bruce,

    Did you try a search string that "ENDS" with a dollar sign? I also
    had no problems with strings with dollar signs in the middle.

    It may be a problem with a resulting layer name ending up identical to
    a layer that's already there. What would you expect in that case?

    The dwg I was fixing has quite a few layers with a lot of
    similar-looking layer names, so it's not easy to work with to resolve
    the problem, and I'm onto editing video now for the rest of the day
    anyway, so I'll have a closer look at it again later.

    Your lisp gave an error after entry of the replace parameter, while
    the one Kitty supplied gave an error after entry of the search
    parameter. It was mostly because of that, not yours, that I guessed
    at a quick assumption about the dollar sign.

    See you later.

    - Tom
    ==================





    Happy Trails To You
     
    Happy Trails, Feb 26, 2006
    #16
  17. Mr. B

    Kitty Guest

    IIRC, autocad help shows the syntax and options for substr and others
    as well.
     
    Kitty, Feb 26, 2006
    #17
  18. Mr. B

    Kitty Guest

    If I remember come monday at the office... several years ago I wrote a
    lisp to search and replace acad text... I suppose I can look it up and
    refresh my memory on how I handled search and replace, and post that
    part of the code....
     
    Kitty, Feb 26, 2006
    #18
  19. Mr. B

    Kitty Guest

    Kitty, Feb 26, 2006
    #19
  20. Mr. B

    Mr. B Guest

    I don't understand because I've replaced many layers that DO have a dollar
    sign in them. I tried using your example:
    TTL-0$AAA
    TTL-0$BBB
    etc....

    Ran my Lisp and got back:
    AAA
    BBB

    I even tried it with three $$$'s... worked fine
    TTL-0$$$AAA
    TTL-0$$$BBB

    How about some examples of your troubled Layers (cut & paste them).

    Regards,

    BruceF
     
    Mr. B, Feb 26, 2006
    #20
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.