Author Topic: Replacing a char with another in a Text  (Read 1501 times)

0 Members and 1 Guest are viewing this topic.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Replacing a char with another in a Text
« 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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Replacing a char with another in a Text
« Reply #1 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))
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.