Re: Deleting substrings



Chris Dollin wrote:
goose wrote:


<snipped>


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.

Not as a criticism of your solution (I'm just piggybacking), but
I wonder what the OP intends to do with

abcxxyydef

After `delete A from B`, is it allowed for the result to contain A?

Er. Requirements error :-) ?


[If not, then we just need to restart the scan not from where we
left off, but from a "suitable distance" before then.]

<speculation>
Would probably be faster to keep it the same (start off where
we stopped) and wrap *that* into a loop which only ends when
no changes are made in the inner loop rather than repeatedly
starting from the beginning of the haystack[1] again (for
arbitrarily long needles[1] "suitable distance" would initially
mean starting from the beginning) each time we make a change.


[1] I use Haystack to mean the long string to be searched and
Needle to mean the short string to find.

Chris "as many cases as corners" Dollin

goose,
"cutting as many corners as there are cases" :-)

.



Relevant Pages

  • Re: Deleting substrings
    ... We start at the beginning of the string. ... How about keeping a record of the first occurrence if the first character ... redundant scans of the host string. ...
    (comp.programming)
  • Re: Programmers unpaid overtime.
    ... > that most programs read multi-GB files into one enormous string, ... > call Split on that string, perhaps multiple times, within loops, ... > a string concatenation within its inner loop. ... > Micro$haft's typical QuickSort implementations? ...
    (comp.programming)
  • Re: coding an anagram function
    ... Exiting the inner loop after the condition is first satisfied, ... not found in the second string and the two are not anagrams. ... Dim I As Long ...
    (microsoft.public.excel.programming)
  • Re: problem with calling subprogram in a nested for-loop
    ... The outer loop works but the inner loop runs only one time ... are assigning a string to $ppm_number, but using it as a number later. ... # 5) generate pmm_G by cropping the source image ... chop $sourcefile_name; ...
    (perl.beginners)
  • Re: trim function dumping core
    ... Chris Dollin wrote: ... I've written a small trim function to trim away the whitespaces in a ... given string. ... char *trim ...
    (comp.lang.c)