change part of text

change part of text

JanneArvid
Participant Participant
268 Views
2 Replies
Message 1 of 3

change part of text

JanneArvid
Participant
Participant

I have this code but i want to change it so i can search and change the last 9 characters of a string of 26 characters?

How do i do?

; Changes textstring if found regardless of block
(vl-load-com)
(defun ChgTxtStrJaar ( / attList a i obj ss)
  (if(setq ss(ssget "_X" '((0 . "INSERT"))))
    (progn
    (repeat(setq i (sslength ss))
      (setq obj (vlax-ename->vla-object(ssname ss(setq i(1- i))))
            attList(vlax-invoke obj 'GetAttributes)
      )
    
      (foreach a attList
        (if(=(vla-get-textstring a)"AAA.B.CCC=ABC.UC001-UCA01") ;Find string...
          (vla-put-textstring a "AAA.B.CCC=ABC.UC551-UCA01") ; ...replace with this
        )
      );foreach
    );repeat
    );progn
  );if
  (princ)
)

 

0 Likes
Accepted solutions (1)
269 Views
2 Replies
Replies (2)
Message 2 of 3

komondormrex
Mentor
Mentor
Accepted solution

hey,

sort of. the string length is actually 25 chars.

 

 

 

 

 

 

(vl-load-com)
(defun ChgTxtStrJaar ( / attList a i obj ss pos_9_end)
  (if(setq ss(ssget "_X" '((0 . "INSERT"))))
    (progn
    (repeat(setq i (sslength ss))
      (setq obj (vlax-ename->vla-object(ssname ss(setq i(1- i))))
            attList(vlax-invoke obj 'GetAttributes)
      )
    
      (foreach a attList
        (if (= (substr (vla-get-textstring a) (setq pos_9_end (1+ (- (strlen (vla-get-textstring a)) 9)))) "001-UCA01") ;Find string...
          (vla-put-textstring a (strcat (substr (vla-get-textstring a) 1 (1- pos_9_end)) "551-UCA01")) ; ...replace with this
        )
      );foreach
    );repeat
    );progn
  );if
  (princ)
)

 

 

or change lines 11-13 with these

 

 

(if (vl-string-search "001-UCA01" (vla-get-textstring a)) 
	(vla-put-textstring a (vl-string-subst "551-UCA01" "001-UCA01" (vla-get-textstring a)))
)

 

 

 

 

0 Likes
Message 3 of 3

JanneArvid
Participant
Participant

Perfect, thx.

The 3 rows was more adjustable and it works fine.

0 Likes