Author Topic: Replacing text string  (Read 3938 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Replacing text string
« Reply #15 on: January 13, 2005, 11:19:33 AM »
maybe a setq around this;
Code: [Select]

(subst (cons 1 (substr str 1 (1- num)))
        (cons 1 str)
        enl
      )
TheSwamp.org  (serving the CAD community since 2003)

whdjr

  • Guest
Replacing text string
« Reply #16 on: January 13, 2005, 11:33:18 AM »
Thanks Mark that fixed it.

Sometimes I get in a hurry and miss the easy things.

By the way I couldn't get yours to work.
It kept coming back nil.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Replacing text string
« Reply #17 on: January 13, 2005, 11:45:30 AM »
well I guess we need to compare dwg's then.  :D
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Replacing text string
« Reply #18 on: January 13, 2005, 03:36:33 PM »
Quote from: CADaver
Where's CAB when you need him, right?

I've got alligators snapping at my a$$ets.  :shock:
I may be scarce for a few days.
BUT here is one I had squirreled away.
Never used it though.
Code: [Select]
;;;Search and Replace TEXT within strings; copyright 1996, H.C. Francis
;;;
;;; AUTHOR: HENRY C. FRANCIS
;;; 425 N. ASHE ST.
;;; SOUTHERN PINES, NC 28387
;;;              
;;; All rights reserved without prejudice.
;;; Copyright: 2-21-96
;;; Edited: 7-15-99
;;;
(DEFUN c:rtext (/ tset  sslen   count    cstrl    nstrl chgstr
cind tild_ind ques_ind numb_ind star_ind strlm
tent strl  wcsrch   str1    str2     istr
      )
  (IF (AND ustr ukword)
    nil
    (LOAD "uutils")
  ) ;_ end of if
  (SETQ chstr   (ustr 1 "String to search for" chstr T)
nwstr   (ustr 0 "String to replace it (~ for nil)" nwstr T)
otstr   (ustr 0
"Additional selection filter (exact match, wildcards ok, ~ for none)"
(IF otstr
  otstr
  nil
)
T
  ) ;_ end of ustr
dozoom   (ukword 1
  "Yes No"
  "Zoom to strings found?"
  (IF dozoom
    dozoom
    "Yes"
  ) ;_ end of if
  ) ;_ end of ukword
curviewctr (GETVAR "viewctr")
  ) ;_ end of setq
  (IF (EQ nwstr "~")
    (SETQ nwstr "")
  ) ;_ end of if
  (IF (EQ otstr "~")
    (SETQ otstr NIL)
  )
  (SETQ cstrl (STRLEN chstr)
nstrl (STRLEN nwstr)
cind 1
strlm 1
cnumb 0
srchlst (IF (AND otstr (/= otstr ""))
 (LIST
   (CONS -4 "<AND")
   (CONS 0 "TEXT")
   (CONS 1 (STRCAT "*" chstr "*"))
   (CONS 1 otstr)
   (CONS -4 "AND>")
 ) ;_ end of list
 (LIST
   (CONS -4 "<AND")
   (CONS 0 "TEXT")
   (CONS 1 (STRCAT "*" chstr "*"))
   (CONS -4 "AND>")
 ) ;_ end of list
) ;_ end of if
  ) ;_ end of setq
  (WHILE (<= cind cstrl)
    (COND
      ((EQ (SUBSTR chstr cind 1) "#")
       (SETQ wcsrch T)
       (SETQ pound_ind cind)
      )
      ((EQ (SUBSTR chstr cind 1) "@")
       (SETQ wcsrch T)
       (SETQ at_ind cind)
      )
      ((EQ (SUBSTR chstr cind 1) ".")
       (SETQ wcsrch T)
       (SETQ period_ind cind)
      )
      ((EQ (SUBSTR chstr cind 1) "?")
       (SETQ wcsrch T)
       (SETQ ques_ind cind)
      )
      ((EQ (SUBSTR chstr cind 1) "#")
       (SETQ wcsrch T)
       (SETQ numb_ind cind)
      )
      ((EQ (SUBSTR chstr cind 1) "*")
       (SETQ wcsrch T)
       (SETQ star_ind cind)
      )
      ((EQ (SUBSTR chstr cind 1) "`")
       (SETQ wcsrch T)
       (SETQ revquote_ind cind)
      )
    ) ;_ end of cond
    (SETQ cind (1+ cind))
  ) ;_ end of while
  (SETQ cind 1)
  (SETQ tset (SSGET srchlst))
  (IF tset
    (PROGN
      (SETQ sslen (SSLENGTH tset)
   count 0
      ) ;_ end of setq
      (WHILE (NOT (>= count sslen))
(SETQ tent (ENTGET (SSNAME tset count))
     tstr (CDR (ASSOC 1 tent))
     strl (STRLEN tstr)
) ;_ end of setq
(IF (OR (NOT (>= strl cstrl)) (= strl 1) wcsrch)
;If search str exceeds current str length, current str length=1 or its a wildcard search
;      (IF (OR(= chstr tstr)(WCMATCH tstr (STRCAT "*" chstr "*")));If current str = new str or
 (PROGN
   (IF (EQ dozoom "Yes")
     (COMMAND ".zoom" "c" (CDR (ASSOC 10 tent)) "")
   ) ;_ end of if
   (GRDRAW (POLAR (CDR (ASSOC 10 tent))
  (+ (GETVAR "viewtwist") (* PI 0.25))
  (CDR (ASSOC 40 tent))
   ) ;_ end of POLAR
   (POLAR (CDR (ASSOC 10 tent))
  (+ (GETVAR "viewtwist") (* PI 1.25))
  (CDR (ASSOC 40 tent))
   ) ;_ end of POLAR
   -1
   0
   ) ;_ end of GRDRAW
   (GRDRAW (POLAR (CDR (ASSOC 10 tent))
  (+ (GETVAR "viewtwist") (* PI 0.75))
  (CDR (ASSOC 40 tent))
   ) ;_ end of POLAR
   (POLAR (CDR (ASSOC 10 tent))
  (+ (GETVAR "viewtwist") (* PI 1.75))
  (CDR (ASSOC 40 tent))
   ) ;_ end of POLAR
   -1
   0
   ) ;_ end of GRDRAW
   (SETQ match_cnt1
  0
 tmp_tstr tstr
   ) ;_ end of SETQ
   (WHILE (NOT (WCMATCH tmp_tstr (STRCAT chstr "*")))
     (SETQ match_cnt1 (1+ match_cnt1)
   tmp_tstr   (SUBSTR tmp_tstr 2)
     ) ;_ end of SETQ
   ) ;_ end of WHILE
   (WHILE (NOT (WCMATCH tmp_tstr chstr))
     (SETQ tmp_tstr (SUBSTR tmp_tstr 1 (1- (STRLEN tmp_tstr))))
   ) ;_ end of WHILE
   (SETQ match_cnt2 (+ match_cnt1 (STRLEN tmp_tstr)))
   (IF (EQ match_cnt1 0)
     (IF (EQ match_cnt2 (STRLEN tstr))
(SETQ istr nwstr)
(SETQ istr (STRCAT nwstr (SUBSTR tstr (1+ match_cnt2))))
     ) ;_ end of IF
     (SETQ istr (STRCAT (SUBSTR tstr 1 match_cnt1)
nwstr
(SUBSTR tstr (1+ match_cnt2))
) ;_ end of strcat
     ) ;_ end of SETQ
   ) ;_ end of IF
   (SETQ tent
  (SUBST (CONS 1 istr)
 (ASSOC 1 tent)
 tent
  ) ;_ end of subst
   ) ;_ end of setq
   (IF (EQ chgstr "Global")
     NIL
     (SETQ
       chgstr
        (ukword 0
        "Yes No Global"
        (STRCAT tstr " Change To:\n" istr "  ?")
        "Yes"
        ) ;_ end of ukword
     ) ;_ end of setq
   )
   (IF (OR (EQ chgstr "Yes") (EQ chgstr "Global"))
     (PROGN
(ENTMOD tent)
(SETQ cnumb (1+ cnumb))
(PRINC "\n ")
     ) ;_ end of progn
   ) ;_ end of if
   (SETQ strlm (1+ strlm)
 cind strl
   ) ;_ end of setq
   (GRDRAW (POLAR (CDR (ASSOC 10 tent))
  (+ (GETVAR "viewtwist") (* PI 0.25))
  (CDR (ASSOC 40 tent))
   ) ;_ end of POLAR
   (POLAR (CDR (ASSOC 10 tent))
  (+ (GETVAR "viewtwist") (* PI 1.25))
  (CDR (ASSOC 40 tent))
   ) ;_ end of POLAR
   -1
   0
   ) ;_ end of GRDRAW
   (GRDRAW (POLAR (CDR (ASSOC 10 tent))
  (+ (GETVAR "viewtwist") (* PI 0.75))
  (CDR (ASSOC 40 tent))
   ) ;_ end of POLAR
   (POLAR (CDR (ASSOC 10 tent))
  (+ (GETVAR "viewtwist") (* PI 1.75))
  (CDR (ASSOC 40 tent))
   ) ;_ end of POLAR
   -1
   0
   ) ;_ end of GRDRAW
 ) ;_ end of progn
;      ) ;_ end of if
 (WHILE
   (NOT (> cind strl))
    (IF
      (EQ
(SUBSTR chstr 1 strlm) ;Str srch'd for trunc'd by mtch'd str lgth
(SUBSTR tstr cind strlm)
;Ex str substr - indx to mtch'd str lgth
      ) ;_ end of eq
(WHILE
 (EQ
   (SUBSTR chstr 1 strlm)
   (SUBSTR tstr cind strlm)
 ) ;_ end of eq
  (IF
    (>= strlm cstrl)
     (PROGN
(IF (EQ dozoom "Yes")
 (COMMAND ".zoom" "c" (CDR (ASSOC 10 tent)) "")
) ;_ end of if
(GRDRAW (POLAR (CDR (ASSOC 10 tent))
      (+ (GETVAR "viewtwist") (* PI 0.25))
      (CDR (ASSOC 40 tent))
) ;_ end of POLAR
(POLAR (CDR (ASSOC 10 tent))
      (+ (GETVAR "viewtwist") (* PI 1.25))
      (CDR (ASSOC 40 tent))
) ;_ end of POLAR
-1
0
) ;_ end of GRDRAW
(GRDRAW (POLAR (CDR (ASSOC 10 tent))
      (+ (GETVAR "viewtwist") (* PI 0.75))
      (CDR (ASSOC 40 tent))
) ;_ end of POLAR
(POLAR (CDR (ASSOC 10 tent))
      (+ (GETVAR "viewtwist") (* PI 1.75))
      (CDR (ASSOC 40 tent))
) ;_ end of POLAR
-1
0
) ;_ end of GRDRAW
(SETQ
 str1
  (IF (= cind 1)
    ""
    (SUBSTR tstr 1 (1- cind))
  ) ;_ end of if
) ;_ end of setq
(SETQ
 str2
  (IF (= cind (1+ strl))
    ""
    (SUBSTR tstr (+ cind cstrl))
  ) ;_ end of if
) ;_ end of setq
(SETQ
 istr
  (STRCAT str1 nwstr str2)
) ;_ end of setq
(SETQ tent
      (SUBST (CONS 1 istr)
     (ASSOC 1 tent)
     tent
      ) ;_ end of subst
) ;_ end of setq
(IF (EQ chgstr "Global")
 NIL
 (SETQ
   chgstr
    (ukword 0
    "Yes No Global"
    (STRCAT tstr " Change To:\n" istr "  ?")
    "Yes"
    ) ;_ end of ukword
 ) ;_ end of setq
)
(IF (OR (EQ chgstr "Yes")(EQ chgstr "Global"))
 (PROGN
   (ENTMOD tent)
   (SETQ cnumb (1+ cnumb))
   (PRINC "\n ")
 ) ;_ end of progn
) ;_ end of if
(SETQ strlm (1+ strlm)
     cind  strl
     tstr  ""
) ;_ end of setq
(GRDRAW (POLAR (CDR (ASSOC 10 tent))
      (+ (GETVAR "viewtwist") (* PI 0.25))
      (CDR (ASSOC 40 tent))
) ;_ end of POLAR
(POLAR (CDR (ASSOC 10 tent))
      (+ (GETVAR "viewtwist") (* PI 1.25))
      (CDR (ASSOC 40 tent))
) ;_ end of POLAR
-1
0
) ;_ end of GRDRAW
(GRDRAW (POLAR (CDR (ASSOC 10 tent))
      (+ (GETVAR "viewtwist") (* PI 0.75))
      (CDR (ASSOC 40 tent))
) ;_ end of POLAR
(POLAR (CDR (ASSOC 10 tent))
      (+ (GETVAR "viewtwist") (* PI 1.75))
      (CDR (ASSOC 40 tent))
) ;_ end of POLAR
-1
0
) ;_ end of GRDRAW
     ) ;_ end of progn
     (PROGN
(SETQ strlm (1+ strlm))
     ) ;_ end of progn
  ) ;_ end of if
) ;_ end of while
    ) ;_ end of if
    (SETQ cind (1+ cind)
  strlm 1
    ) ;_ end of setq
 ) ;_ end of while
) ;_ end of if
(SETQ count (1+ count)
     strlm 1
     cind  1
) ;_ end of setq
      ) ;_ end of while
      (IF (NOT (EQUAL curviewctr (GETVAR "viewctr")))
(COMMAND ".zoom" "c" curviewctr "")
      ) ;_ end of if
      (PRINC (STRCAT "\n"
    (ITOA cnumb)
    " \""
    chstr
    "\" strings were replaced with \""
    nwstr
    "\" strings."
    ) ;_ end of strcat
      ) ;_ end of princ
    ) ;_ end of PROGN
    (PRINC "\nNo matching strings found! ")
  ) ;_ end of IF
  (PRINC)
) ;_ end of defun

;|«Visual LISP© Format Options» (72 2 40 2 T "end of " 60 9 2 0 0 T T nil T)
 ***Don't add text below the comment!***|;
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
Replacing text string
« Reply #19 on: January 13, 2005, 07:59:03 PM »
WOW!

That one is way to long to even attempt to rewrite with todays code.