| Paste number 83013: | untitled |
| Pasted by: | egn |
| When: | 2 years, 7 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1S1X |
| Channel: | None |
| Paste contents: |
(defun replace-all (string part replacement &key (test #'char=))
"Returns a new string in which all the occurences of the part is replaced with replacement."
(with-output-to-string (out)
(loop with part-length = (length part)
for old-pos = 0 then (+ pos part-length)
for pos = (search part string
:start2 old-pos
:test test)
do (write-string string out
:start old-pos
:end (or pos (length string)))
when pos do (write-string replacement out)
while pos))) This paste has no annotations.