The replacement need not be serial i.e. can be
done in parallel. See
http://www.jsoftware.com/jwiki/Essays/Non-Overlapping_Substrings
A good test case for non-overlap would be:
original string: aaaaaa
replace aa by baa
result: baabaabaa
Notepad does it like "stringreplace" where the
substrings don't overlap. I myself prefer
non-overlaps as the results seem less surprising.
----- Original Message -----
From: Devon McCormick <[EMAIL PROTECTED]>
Date: Friday, March 2, 2007 8:42 am
Subject: [Jprogramming] string-replace variations
> Recent correspondence alerted me to the existence of an
> existing standard J function that I ought to use in place of a
> version I wrote. However, on reflection, I thought of a case
> where the two are not equivalent:
>
> ('AA';'B') stringreplace 'AAA'
> BA
> ('AA';'B') replace 'AAA'
> BB
>
> The latter simultaneously replaces both instances of "AA"
> (the instance starting at position 0 and the one at position 1)
> with "B"; the former is apparently replacing serially so doesn't
> see the second, overlapping occurrence of "AA".
>
> Does anyone have a thought to which behavior is "correct"
> or at least better?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm