mrdd Posted September 11, 2012 Share Posted September 11, 2012 Hello Here's my problem. I ve got hundreds of texts contain letters and numbers like this 'TT01 23+566.66' 'TT02 22+364.64' 'TT03 28+556.89'. So i need the first part of the text which is TT'number' to be removed. I cant do that with the basic find and replace tool because numbers are different. Is there any lisp you know to handle this? Quote Link to comment Share on other sites More sharing options...
pBe Posted September 11, 2012 Share Posted September 11, 2012 (substr str 6) if TT'number' length varies: i.e "TT105 28+556.89" then use (substr str (+ (vl-string-position 32 str) 2)) HTH Quote Link to comment Share on other sites More sharing options...
Dadgad Posted September 11, 2012 Share Posted September 11, 2012 When in doubt, check Lee Mac out. His BATCH FIND AND REPLACE should do the trick. http://www.lee-mac.com/bfind.html Thanks Lee! Quote Link to comment Share on other sites More sharing options...
cadplayer Posted September 11, 2012 Share Posted September 11, 2012 (edited) You can also use this : (defun STRFIND (SRC SRCH / CNT RET ) (setq CNT 1) (while (<= CNT (strlen SRC)) (if (= (substr SRC CNT (strlen SRCH)) SRCH) (setq RET (list (substr SRC 1 (1- CNT)) (substr SRC (+ CNT (strlen SRCH)))) CNT (1+ (strlen SRC)) ) (setq CNT (1+ CNT)))) (if (null RET) (list SRC nil) RET)) (defun c:test (/ STR) (setq STR (getstring "\nType in a string: ")) (while (/= (and (setq SSTR (car (entsel "\nSelect a string to change: "))) (if (= (type (cdr (assoc 1 (entget SSTR)))) 'STR) (progn (setq RES (strfind (cdr (assoc 1 (entget SSTR))) STR)) (entmod (subst (cons 1 (strcat (car RES) (cadr RES))) (assoc 1 (entget SSTR)) (entget SSTR) ) ) ) ) ) ) ) (princ) ) Edited September 11, 2012 by cadplayer Quote Link to comment Share on other sites More sharing options...
SLW210 Posted September 11, 2012 Share Posted September 11, 2012 cadplayer, You need to place your code in CODE TAGS not quote tags. Quote Link to comment Share on other sites More sharing options...
cadplayer Posted September 11, 2012 Share Posted September 11, 2012 Thanks Take it easy Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 11, 2012 Share Posted September 11, 2012 As pBe correctly suggests, the substr function is the key for this task: (defun c:txtupd ( / e i s x ) (if (setq s (ssget "_:L" '((0 . "TEXT") (1 . "TT## *")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i)))) x (assoc 1 e) ) (entmod (subst (cons 1 (substr (cdr x) 6)) x e)) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
wishbonesr Posted September 20, 2012 Share Posted September 20, 2012 In case it's needed, more complex regular expressions could be used with acet-str-replace, provided Express Tools are installed. See http://www.afralisp.net/archive/lisp/acet-utils.htm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.