Happy Hobbit Posted November 5, 2015 Share Posted November 5, 2015 I'm trying to use the vl-string-translate function to replace a character within a text string thus: (defun c:test ( / a b ) (setq a (entget(car(entsel)))) (setq b(cdr(assoc 1 a))) (princ (vl-string-translate "NO." "No." b)) ) But after many experiments in the Console all I keep getting is BoILER No. 2 instead of BOILER No. 2. Anyone know how to make vl-string-translate only find an "o" when preceded by a "N" ? Quote Link to comment Share on other sites More sharing options...
hmsilva Posted November 5, 2015 Share Posted November 5, 2015 Try vl-string-subst (defun c:test ( / a b ) (setq a (entget(car(entsel)))) (setq b(cdr(assoc 1 a))) (princ (vl-string-subst "No." "NO." b)) ) Henrique Quote Link to comment Share on other sites More sharing options...
Happy Hobbit Posted November 5, 2015 Author Share Posted November 5, 2015 (edited) Henrique, thank you very much. I've not seen that one before. All I've got to do is put in an entmod now (defun c:test ( / a b ntext) (setq a (entget(car(entsel)))) (setq b(cdr(assoc 1 a))) (setq ntext (vl-string-subst "No." "NO." b)) (entmod(subst (cons 1 ntext) (assoc 1 a) a)) ) (vl-load-com) Edited November 5, 2015 by Happy Hobbit Quote Link to comment Share on other sites More sharing options...
hmsilva Posted November 5, 2015 Share Posted November 5, 2015 You're welcome! Glad I could help Henrique Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 6, 2015 Share Posted November 6, 2015 If your using Vl why not all, saves remembering dxf codes (defun c:test ( / a b ntext) (setq obj (vlax-ename->vla-object (car(entsel)))) (setq b (vla-get-textstring obj)) (setq ntext (vl-string-subst "No." "NO." b)) (vla-put-textstring obj ntext) ) (vl-load-com) Quote Link to comment Share on other sites More sharing options...
Happy Hobbit Posted November 6, 2015 Author Share Posted November 6, 2015 If your using Vl why not all, saves remembering dxf codes Good plan BIGAL. Thank you v much, I shall give it a try when I get into work soon. I've only just (this month) entered the realm of VL type functions, & this is my first attempt. As you can see from the poorly chosen VL from the subject, I'm somewhat inexperienced, although I've copied other folks VL code before. 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.