Happy Hobbit 发表于 2022-7-5 18:25:04

vl-string-translate

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" ?

hmsilva 发表于 2022-7-5 18:46:28

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

Happy Hobbit 发表于 2022-7-5 19:00:19

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)

hmsilva 发表于 2022-7-5 19:09:46

You're welcome!
 
Glad I could help
Henrique

BIGAL 发表于 2022-7-5 19:13:47

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)

Happy Hobbit 发表于 2022-7-5 19:37:00

 
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.
页: [1]
查看完整版本: vl-string-translate