or better:
;
; Multiple substitution of a pattern string - 05/21/03
; Original by John Uhden, added SttPos argument
;
; Arguments:
; NewStr: the string to be substituted for pattern
; PatStr: a string containing the pattern to be replaced ; InpStr: the string to be searched for pattern ; SttPos: 0, nil or an integer identifying the starting position of the search ; ; Return Values: the value of string after any substitutions have been made ; ; Example:
; (ALE_StringSubstAll "new" "old" "old test for old method" nil) ; ; Notes:
; the search is case-sensitive
; SttPos = 0 or nil > substitution start from first character ; NewStr = "" remove all instances of PatStr from SttPos ; ; Suggestions:
; use (vl-string-translate "\t" " " "Hi\tthis\tis\ta\ttest!") ; for single (or set) character substitution (not to remove) ; (N.B. the inversion of arguments) ; (defun ALE_StringSubstAll (NewStr PatStr InpStr SttPos / NewLen) (setq NewLen (strlen NewStr)) (while (setq SttPos (vl-string-search PatStr InpStr SttPos)) (setq InpStr (vl-string-subst NewStr PatStr InpStr SttPos) SttPos (+ SttPos NewLen) ) ) InpStr )