Re: Deleting substrings
- From: rossum <rossum48@xxxxxxxxxxxx>
- Date: Thu, 29 Jun 2006 12:43:29 +0100
On 28 Jun 2006 13:43:56 -0700, "Ravi" <ravib.1981@xxxxxxxxx> wrote:
A function which takes a string and a substring as input and whichAn alternative without recursion would be to use a state machine to
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.
copy the characters you want from the source string to the destination
string. Something like:
[Monospaced font recommended]
State Character Actions New State
======= ========= ============ =========
Copying 'x' step 1 x-found
Copying \0 copy \0 Finish
Copying ~'x', ~\0 copy current Copying
step 1
x-found 'y' step 1 Copying
x-found \0 copy 'x' Finish
copy \0
x-found ~'y', ~\0 copy 'x' Copying
copy current
step 1
Finish any return
I have assumed C-style strings with a \0 terminator. The step 1
action moves the source index forward one. The copy action copies the
character to the destination and increases the destination index by
one. "copy current" copies whatever character is currently at the
source index and increases the destination index by one. The two
logical strings can be the same piece of memory as the destination
cannot be longer than the source.
.
- References:
- Deleting substrings
- From: Ravi
- Deleting substrings
- Prev by Date: Re: Any online source management for personal projects ?
- Next by Date: Re: ls lacking a feature?
- Previous by thread: Re: Deleting substrings
- Next by thread: ls lacking a feature?
- Index(es):
Relevant Pages
|