TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Tharwat on June 30, 2010, 05:34:14 AM

Title: Replacing a char with another in a Text
Post by: Tharwat on June 30, 2010, 05:34:14 AM
Hi
I want to replace a specific chars from the first text and replace it with another within the text selection .
I have reach to the end but the result is nil ..... I think the use of - subst - is not correct.
any help would be appreciated ..
Code:
Code: [Select]
(defun c:txt (/ 1txt 2txt curTxt entTxt all pt)
  (vl-load-com)
(setq 1txt (getstring"\nEnter the old Char.:"); example   123
      2txt (getstring"\nEnter the replaced Char.:"); example the
      curTxt(car(entsel"\nSelect Text:")); Ref123ok
      entTxt(cdr (assoc 2 (entget curTxt)))
      )
(setq all (subst (2txt) (1txt) entTxt)
      hgt (cdr (assoc 40 (entget curTxt))))
(setq pt (getpoint"\nNew text Location: "))
  (command "_.text" pt  hgt "" all "")
  (princ)
  )
; result must be = Reftheok
Regards
Tharwat
Title: Re: Replacing a char with another in a Text
Post by: Kerry on June 30, 2010, 06:45:28 AM

perhaps something like

Code: [Select]
(setq 1txt   "123"
      2txt   "the"
      curTxt "Ref123ok"
)

(setq result (VL-STRING-SUBST 2txt 1txt curTxt))