Hi,
I'm looking for an easy (efficiency is not a factor) way to replace
string x with string y in string z. This is not homework (I take no
CS classes) so I'm not looking for a detailed character by character
way as sometimes seen in books but rather for the quick idiomatic
way. When I post I usually show my attempt at the problem but here
I'm looking for ideas on where to start rather than corrections to
my code. I'd appreciate all suggestions on what functions to look
at or where to start to do this, because I'm clueless on how to
start writing this function.
Thanks a lot,
--
Jordan Katz <····@underlevel.net> | Mind the gap
"Jordan Katz" <····@underlevel.net> wrote in message
···················@underlevel.underlevel.net...
> Hi,
>
> I'm looking for an easy (efficiency is not a factor) way to replace
> string x with string y in string z. This is not homework (I take no
> CS classes) so I'm not looking for a detailed character by character
> way as sometimes seen in books but rather for the quick idiomatic
> way. When I post I usually show my attempt at the problem but here
> I'm looking for ideas on where to start rather than corrections to
> my code. I'd appreciate all suggestions on what functions to look
> at or where to start to do this, because I'm clueless on how to
> start writing this function.
There seems to be two cases, where x and y are the same length and when x
and y are different lengths. The CLHS section on sequences seems most
appropriate.
CL-USER 1 > (setf string "hello123world")
"hello123world"
CL-USER 2 > (search "123" string)
5
CL-USER 5 > (replace string "out" :start1 (search "123" string))
"hellooutworld"
CL-USER 11 > (setf string "hello123world")
"hello123world"
CL-USER 12 > (let ((position (search "123" string)))
(concatenate 'string
(subseq string 0 position)
" "
(subseq string (+ position (length "123")))))
"hello world"
CL-USER 13 >
From: Christopher C. Stacy
Subject: Re: replacing strings.
Date:
Message-ID: <u662pllty.fsf@grant.org>