Sanırım standartta böyle bir işlev yok. Eğer normal bir ifade (cl-ppcre) kullanmak istemiyorsanız, bu kullanabilirsiniz:
(defun string-replace (search replace string &optional count)
(loop for start = (search search (or result string)
:start2 (if start (1+ start) 0))
while (and start
(or (null count) (> count 0)))
for result = (concatenate 'string
(subseq (or result string) 0 start)
replace
(subseq (or result string)
(+ start (length search))))
do (when count (decf count))
finally (return-from string-replace (or result string))))
DÜZENLEME: Shin Aoyama bu "\\\""
ile, örneğin değiştirilmesi için "\""
çalışmıyor dikkat çekti "str\"ing"
. Şimdi sıra oldukça hantal yukarıda kabul beri çok daha iyidir Common Lisp Cookbook verilen uygulama, teklif etmeli:
(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)))
Özellikle genellikle concatenate
daha iyi performans with-output-to-string
kullanımı gibi.
http://stackoverflow.com/questions/90977/replace-char-in-emacs-lisp kopyası mı? – khachik
Ortak lisp olmalı ve herhangi bir ek kitaplık yüklemek istemiyorum. Ben sadece SLIME var. –
Elisp çözümlerini istemiyorsanız, soruyu elisp ile etiketlememelisiniz. – sepp2k