I use the following on occasion. It assumes that the ff
character does not occur in the text or in the replacement
string. Also, if overlapping substrings need to be handled,
you have to replace E. by nos in
http://www.jsoftware.com/jwiki/Essays/Non-Overlapping_Substrings
The code for q longer than p should work for the case
where q is not longer than p. The extra code is probably
due to its being faster.
ff=: {: a.
NB. x is text; y is (p;q); replace all occurrences of p by q in x
replace=: 4 : 0
'p q'=. y
d=. p -&# q
b=. p E. x
if. 0<:d do. NB. replacement string not longer
ff -.~ (q,d$ff) ((I. b) +/ i.#p)}x
else. NB. replacement string longer
((b i. 1){.x) , ; q&,&.>(#p)}.&.>b <;.1 x
end.
)
----- Original Message -----
From: "L.Tomei" <[EMAIL PROTECTED]>
Date: Thursday, November 13, 2008 7:50
Subject: RE: [Jprogramming] tacit stringreplace
To: [email protected]
>
> So, let we start to the target of 100.000 posts on J forums.
>
> Coming back to stringreplace, I understand your explanation
> about "tacit vs
> explicit".
> But I still think that the stringreplace verb defined in
> string.ijs could be
> improved, at least for some kinds of replacements.
> My feel is that 50 (about) lines of J code, even if optimized,
> are too much
> for fhis function.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm