Re: Deleting substrings



Ravi said:

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 ?

No. You can use iteration.

How to handle the deletion part..I mean deleting a substring and then
starting all over again looking for the next substring.

Find the xy substring:

abcxyghixywhowantsxytosearchxyforever
^

Remove it:

abcghixywhowantsxytosearchxyforever
^

Starting at that point, find the next xy substring:

abcghixywhowantsxytosearchxyforever
^

Remove it:

abcghiwhowantsxytosearchxyforever
^

Starting at that point, find the next xy substring:

abcghiwhowantsxytosearchxyforever
^

Remove it:

abcghiwhowantstosearchxyforever
^

Starting at that point, find the next xy substring:

abcghiwhowantstosearchxyforever
^

Remove it:

abcghiwhowantstosearchforever
^

Starting at that point, find the next xy substring, oh, there isn't one, I
guess we're done here.



--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages

  • Re: Function speed, which is fast
    ... >> where substring is a substring of the whole file, ... >> found and currentchar is the character being examined in this iteration of ... With a buffer full of 0s they ...
    (comp.lang.pascal.delphi.misc)
  • Re: Function speed, which is fast
    ... > where substring is a substring of the whole file, ... > found and currentchar is the character being examined in this iteration of ...
    (comp.lang.pascal.delphi.misc)
  • Re: Deleting substrings
    ... Will it require recursion? ... How to handle the deletion part..I mean deleting a substring and then ... I would assume that delete the substring means removes all instances of it, but removing all instances of a substring does not necessarily mean that the resulting string will not contain instances of it. ...
    (comp.programming)
  • Re: Deleting substrings
    ... deletes the substring in the main string. ... Will it require recursion? ... How to handle the deletion part..I mean deleting a substring and then ...
    (comp.programming)
  • Deleting substrings
    ... deletes the substring in the main string. ... Will it require recursion? ... How to handle the deletion part..I mean deleting a substring and then ...
    (comp.programming)