String Subst
| Function Syntax | (LM:stringsubst <new> <old> <str>) |
| Current Version | 1.0 |
| Donate |
| Arguments | ||
|---|---|---|
| Symbol | Type | Description |
| new | String | String to be substituted for 'old' |
| old | String | String to be replaced |
| str | String | String to be searched |
| Returns | ||
| Type | Description | |
| String | String with all occurrences of 'old' replaced with 'new' | |
Program Description
This subfunction will substitute all occurrences of a string for another string within a string.
The functionality is similar to the Visual LISP vl-string-subst (and indeed uses this function), however, this subfunction performs a global replacement, hence all occurrences of the pattern string are replaced.
Select all
;; String Subst - Lee Mac ;; Substitutes a string for all occurrences of another string within a string. ;; new - [str] String to be substituted for 'old' ;; old - [str] String to be replaced ;; str - [str] String to be searched ;; Returns string with all occurrences of 'old' replaced with 'new' (defun LM:stringsubst ( new old str / inc len ) (setq len (strlen new) inc 0 ) (while (setq inc (vl-string-search old str inc)) (setq str (vl-string-subst new old str inc) inc (+ inc len) ) ) str )
Example Function Call
_$ (LM:stringsubst "lisp" "be" "To be or not to be") "To lisp or not to lisp"
