ReplaceInString

Replace any character with a fixed char

(make-string (length word) 0)

replace-regexp-in-string

Emacs21 already has what you need:

(replace-regexp-in-string "fo+" "baz" "da foo is foobared")

 => "da baz is bazbared"

Dired

dired.el already has what you need:

(require 'dired)
(dired-replace-in-string "fo+" "baz" "da foo is foobared")

 => "da baz is bazbared"

Splitting and Joining Strings

You can use the regexp you want to replace as a separator while splitting a string into a list, and join the strings back using your replacement as the new separator.

(mapconcat ‘identity (split-string “da foo is foobared” “fo+”) “baz” )

 => "da baz is bazbared"

</pre>

Note that in Emacs 21 and earlier, leading and trailing matches against the separator will be lost (Emacs 22.1 adds the OMIT-NULLS argument to control this).


CategoryCode