Re: I can't believe: replace string in a string (without tampering a buffer) - does not exist
"Pascal J. Bourguignon" <[email protected]> Thu, 21 Jul 2011 23:12:54 +0200
| Newsgroups | gmane.comp.gnu.utils |
|---|---|
| Organization | Informatimago |
| Message-ID | <[email protected]> |
Swami Tota Ram Shankar <[email protected]> writes: > Subject - I can't believe: replace string in a string (without > tampering a buffer) - does not exist > > Hello colleagues, > > I am simply trying to replace a string by a string in another string. > This is so that can cook it, ie do replacements in a context without > having to match/coordinates/narrow/widen steps, and thus check prior > to running the final replacement. I prefer to be helped with a simple > lisp function, perhaps a lambda or some nested operations than a > defun. > > I have done my homework before asking for help, and used the function > replace-regexp-in-string > but the regexp is written as a string and can have wild-cards > characters so I dont like it as compared to a literal string. If there > is an option in it to make it literal easily without extensive > quoting, then I am not familiar with it. Why do you want to avoid extensive quoting? (defun replace-in-string (new old string) (let ((case-fold-search nil)) (replace-regexp-in-string (regexp-quote old) new string t))) (replace-in-string "Pascal" "{NAME}" "Hello {NAME}!") --> "Hello Pascal!" > replace is an autoloaded Lisp function in `cl-seq'. > [Arg list not available until function definition is loaded.] > not documented It's documented by the Common Lisp standard. http://www.lispworks.com/documentation/HyperSpec/Front/index.htm http://www.lispworks.com/documentation/HyperSpec/Body/f_replac.htm#replace -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.