Lisp Question regarding obtaining parts of a String

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
substr STRNG 0,6 ? (starting from zero, six characters) Argusy
Mr. B wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Does this mean you'll be updating that RenLyr lisp to replace strings anywhere, not just at the front?
Happy Trails To You
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Mr. B wrote:

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....
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Sure. Please do that.
Regards,
BruceF
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Mr. B wrote:

Okay, I found the lisp... I still use it ;) But for the life of me, I don't remember what was what in it... well, in 5 minutes or less. I used to do a lot more lisping few years back, i'm starting to forget things :( Mind you, this is not for layers, but to search and replace regular acad text.
;search and replace text - written circa 1998 by CB (defun C:EDT (/ adj p l n e os as ns st s nsl osl sl si chf chm) (setq p (ssget)) ;Select objects (if p (progn ;If any objects selected... (setq osl (strlen (setq os (getstring "\nOld string: " t)))) (setq nsl (strlen (setq ns (getstring "\nNew string: " t)))) (setq l 0 chm 0 n (sslength p)) (setq adj (cond ((/= osl nsl) (- nsl osl)) (T nsl) ) ) (while (< l n) (if (= "TEXT" (cdr (assoc 0 (setq e (entget (ssname p l)))))) (progn (setq chf nil si 1) (setq s (cdr (setq as (assoc 1 e)))) (while (= osl (setq sl (strlen (setq st (substr s si osl))))) (if (= st os) (progn (setq s (strcat (substr s 1 (1- si)) ns (substr s (+ si osl)))) (setq chf t) (setq si (+ si adj)) )) (setq si (1+ si)) ) (if chf (progn (setq e (subst (cons 1 s) as e)) (entmod e) (setq chm (1+ chm)) )) ) ) (setq l (1+ l)) ) )) (princ "Changed ") (princ chm) (princ " text lines.") (terpri) )
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Happy Trails wrote:

http://www.itcad.net/RenameLayer.htm#Topic24
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Happy Trails wrote:

Hmmm, now you guys got me puzzled. I remember renaming many many xrefed, bound and exploded lsayers back in the day when we were limited to (I think 32) characters in a layer name... what was that, R13 and R14... Don't recall having trouble with dollar signs. If I can sneak some time over next few days I'll have a look at it... Can't promise I'll have time to get to the bottom of it.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I think it is a duplicate layer issue. I don't have any problems with $ symbols.
Regards,
BruceF
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Mr. B wrote:

Yea, I'm inclined to think in that direction too...
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I tried it just now... not an issue. My test strings were like: AAA$aaa AAA$bbb AAA$ccc
And I got rid of the AAA$ part no problemo...

This has happened to me. All you can do when you get a duplicate layer name is to manually change them if you can't find a string to replace.

If you have a lot of drawings to do, the easiest thing I could think of is to have a Lisp routine to rename the layers for you .
(Defun C: ChgLyr ( )
(if (TblSearch "Layer" "CurrName") (command "-Rename" Layer" "CurrName" "NewName") ) ; if
(princ) ) ; defun
You have the above table search for Each Layer you want to change. CurrName is your Existing Layer name. NewName is your New Layer name.
Then just run this for each of your drawings and voila'... It is a basic IF THEN kind of statement.
If the Layer does not exist, nothing happens.
This is a bit harder. But if you have a lot of drawings, I think your up front work will help out if they all have similar layers (and especially if you know you'll get more drawings from where those ones you have came from).
Regards,
BruceF
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
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
Mr. B wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I hear you. I also program in VB.net and VB6 and I too get confused/forgetful sometimes on the syntax. (:
Regards,
BruceF
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
(Mr. B) wrote:

Just to butt in, The R12 AutoLisp Programmers Reference book shows it on page 158. Perhaps you have some other book?
Brian.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.