;; | --------------------------------------------------------------------------- ;; | ST_ReplPattern ;; | --------------------------------------------------------------------------- ;; | Function : Replace a given pattern in a string with another pattern ;; | Arguments : 'Str' - String to check ;; | 'Pat1' - Pattern to search ;; | 'Pat2' - Pattern to replace ;; | 'CaseSens' - If T, the search will be case-sensitive else no ;; | Return : The string after the pattern has been replaced. ;; | This is a case-sensitive search and replace ;; | Updated : April 23, 2004 ;; | e-mail : rakesh.rao@4d-technologies.com ;; | Web : www.4d-technologies.com ;; | --------------------------------------------------------------------------- (defun ST_ReplPattern ( Str Pat1 Pat2 CaseSens / newStr pos More len _Str ) (setq newStr "" More T len (strlen Pat1) ) (if CaseSens (setq _Str Str) (setq _Str (strcase Str) Pat1 (strcase Pat1) ) ) (while More (setq pos (ST_FindPattern _Str Pat1)) (if pos (progn (setq newStr (strcat newStr (substr Str 1 (1- pos)) Pat2) Str (substr Str (+ pos len)) _Str (substr _Str (+ pos len)) ) (if (= Str "") (setq More nil) ) ) (setq newStr (strcat newStr Str) More nil )) ) newStr )