Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I can't believe: replace string in a string (without tampering a buffer) - does not exist

20 views
Skip to first unread message

Swami Tota Ram Shankar

unread,
Jul 21, 2011, 4:34:16 PM7/21/11
to
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.

I searched and found replace but could not figure out what it does.

My work is stuck on it and your help would be appreciated.

replace is an autoloaded Lisp function in `cl-seq'.
[Arg list not available until function definition is loaded.]
not documented

so I tried to use it (correctly or incorrectly) as follows and it
loaded

(replace "2" "3" "333222" )

replace is a compiled Lisp function in `cl-seq'.
(replace CL-SEQ1 CL-SEQ2 &rest CL-KEYS)

Replace the elements of SEQ1 with the elements of SEQ2.
SEQ1 is destructively modified, then returned.
Keywords supported: :start1 :end1 :start2 :end2

Swami Tota Ram Shankar

Pascal J. Bourguignon

unread,
Jul 21, 2011, 5:12:54 PM7/21/11
to
Swami Tota Ram Shankar <tota...@india.com> 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 {}.

Message has been deleted
0 new messages