Re: Deleting substrings
- From: "goose" <ruse@xxxxxxxxxxxxx>
- Date: 29 Jun 2006 02:35:55 -0700
Ravi wrote:
A function which takes a string and a substring as input and which
deletes the substring in the main string.
Eg: mainstr=abcxyghixy sub=xy
Result should be mainstr=abcghi.
Will it require recursion ?
How to handle the deletion part..I mean deleting a substring and then
starting all over again looking for the next substring.
Well, you don't have to start all over again; you can always
start looking again at the point that you last stopped.
1. We start at the beginning of the string.
abcxyghixy
^
2. We scan from that point for "xy" and if we don't find it
then we are done, if we find it then we are at the following point
in the string:
abcxyghixy
^
3. We copy the characters from the point immediately after
"xy" into the current position:
abcghixy
^
4. We repeat steps 2 and 3 until step 2 tells us that we are done.
goose,
btw:
This might be an ideal time for you to read up on
state-machines and attempt to rework the solution
above into a state-machine as it looks like a nice
and simple machine suitable for a first state-machine.
.
- Follow-Ups:
- Re: Deleting substrings
- From: Chris Dollin
- Re: Deleting substrings
- References:
- Deleting substrings
- From: Ravi
- Deleting substrings
- Prev by Date: Re: ls lacking a feature?
- Next by Date: Re: Merging two sorted arrays in place
- Previous by thread: Re: Deleting substrings
- Next by thread: Re: Deleting substrings
- Index(es):
Relevant Pages
|