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

replacing strings.

3 views
Skip to first unread message

Jordan Katz

unread,
Apr 17, 2002, 10:35:48 PM4/17/02
to
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 <ka...@underlevel.net> | Mind the gap

Christopher C. Stacy

unread,
Apr 17, 2002, 11:36:25 PM4/17/02
to
You might start with SEARCH, SETF and SUBSEQ.

Wade Humeniuk

unread,
Apr 18, 2002, 12:03:21 AM4/18/02
to

"Jordan Katz" <ka...@underlevel.net> wrote in message
news:m3elhdu...@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 >


0 new messages