I think I wrote it right ...
"snr" == "Search'N Replace"
)save
2016-06-21 15:11:40 (GMT-4) CONTINUE
s
Ceci est du texte
s snr " " "."
.Ceci...est..du.....texte....
s snr " " " "
Ceci est du texte
s snr " " " "
Ceci est du texte
s snr " " " "
Ceci est du texte
s snr " " " "
Ceci est du texte
s snr " " " "
Ceci est du texte
s snr " " ""
Ceci estdu texte
s snr " " ""
Ceciestdutexte
s snr "" " "
C e c i e s t d u t e x t e
∇z←s snr p;⎕io;fr;to;i;P
⎕io←1
(fr to)←p
s←,s ⋄ fr←,fr ⋄ to←,to
z←¯1↓∧/[1](¯1+⍳⍴fr)⌽fr∘.=s,⎕ucs 1
i←0
Sanitize: i←i+1
→(i≥⍴z)/Substitute
→(0=z[i])/Sanitize
((⊂ i+¯1+⍳⍴fr)⌷z)←(⍴fr)↑1
→Sanitize
Substitute: P←⌽(z/⍳⍴z)
z←s
Loop: →(0=⍴P)/0
z←((¯1+P[1])↑z),to,(¯1+P[1]+⍴fr)↓z
P←1↓P
→Loop
∇
⍝ only need some midnight Oil ;-)
Xtian.
On 2016-06-21 12:27, Juergen Sauermann wrote:
Hi Xtian,
how about this:
*
**s←"444This4is4a4444test44with44444lot4of4blanks4444at4beginning4and444end444444"**
from←"444"**
** to←"5"**
**
** ↑⍎')HOST echo "',s,'" | sed s/',from,'/',to,'/g'**
**5This4is4a54test44with544lot4of4blanks54at4beginning4and5end55**
** **
*I have replaced the *^* in your example because it (and some other characters)
have a special meaning in
regular expressions. But the special characters can be easily quoted in APL if
needed, for example:
*
s←"^^^This^is^a^^^^test^^with^^^^^lot^of^blanks^^^^at^beginning^and^^^end^^^^^^"
**
** ((s='^')/s)←⊂'\^'**
** ⊃,/s**
**\^\^\^This\^is\^a\^\^\^\^test\^\^with\^\^\^\^\^lot\^of\^blanks\^\^\^\^at\^beginning\^and\^\^\^end\^\^\^\^\^\^**
*
/// Jürgen
On 06/21/2016 05:12 AM, Christian Robert wrote:
Hi, it's not a bug but a request for help,
suppose
s="^^^This^is^a^^^^test^^with^^^^^lot^of^blanks^^^^at^beginning^and^^^end^^^^^^"
suppose from="^^^"
suppose to="^"
I need a function who can replace ("^^^" to "^"), or ("^" to "^^^^^^^^") or ("" to
"blabla" with limits of source size) ie: without being lost in infinite loop.
"s" is a character vector, "from" is a character vector, and "to" is a
character vector,
both "s", "from" and "to" can be "".
I'm pretty sure this idiom already exist.
if you can help me, please do.
Xtian.