;-------------------------------
; Change Text String 30.6.91 AW
;-------------------------------
(Defun C:Ct ()
  (Setvar "Cmdecho" 0)
  (Setq B 0)
  (Initget 1 "G P")
  (Setq F (Getkword "Change text - Global/Part: "))
  (Setq A (Ssget))
  (If
    A
      (Cond
        ((= F "G")
          (Repeat
            (Sslength A)
            (If
              (/= "TEXT"
                (Cdr (Assoc 0 (Setq E (Entget (Setq C (Ssname A B))))))
              )
                (Setq B (1+ B))
                (Progn
                  (Command "WAHL" C)
                  (Setq G (Strlen (Setq D
                    (Getstring t "\nNew Text: ")))
                  )
                  (Setq H (Cdr (Assoc 1 E)))
                  (Cond
                    ((And (/= D "") (= "<>" (Substr D 1 2)))
                      (Setq D (Strcat H (Substr D 3 (- G 2))))
                    )
                    ((And (/= D "") (= "<>" (Substr D (- G 1) 2)))
                      (Setq D (Strcat (Substr D 1 (- G 2)) H))
                    )
                  )
                  (If
                    (/= D "")
                      (Progn
                        (Setq E (Subst (Cons 1 D) (Assoc 1 E) E))
                        (Entmod E)
                      )
                  )
                  (Setq B (1+ B))
                  (Command "")
                )
            )
          )
        )
        ((= F "P")
          (Progn
            (Setq D (Strlen (Setq C (Getstring t "\nOld String: "))))
            (Setq G (Getstring t "\nNew String: "))
            (Princ "\nWorking...")
            (Repeat
              (Sslength A)
                (Princ ".")
                (If
                  (= "TEXT" (Cdr (Assoc 0 (Setq E (Entget (Ssname A B))))))
                    (Progn
                      (Setq K (Cdr (Assoc 1 E)))
                      (Setq H 1)
                      (If
                        (= C (Substr G (- (Strlen G) (- (Strlen C) 1))))
                          (Setq I D)
                          (Setq I 0)
                      )
                      (While
                        (= D (Strlen (Setq J (Substr K H D))))
                          (Princ ".")
                          (If
                            (= J C)
                              (Progn
                                (Setq K (Strcat (Substr K 1 (1- H)) G
                                  (Substr K (+ H D)))
                                )
                                (Setq H (+ (- (Strlen G) 1) H I))
                              )
                              (Setq H (1+ H))
                          )
                      )
                      (If
                        (/= K (Cdr (Assoc 1 E)))
                          (Progn
                            (Setq E (Subst (Cons 1 K) (Assoc 1 E) E))
                            (Entmod E)
                          )
                      )
                    )
                )
                (Setq B (1+ B))
            )
          )
        )
      )
  )
  (Princ)
)
