Chris,
These are not optimised but they have the functionality
'2018-03-23 T 18:25:04
'REPLACE / REPLACE ANY
'
sub replace(byref s as string,byval w as string, byval r as string)
'==================================================================
'
dim as sys a,lw,lr
'
lw=len(w) : if lw=0 then exit sub
lr=len(r)
do
a=instr(a+1,s,w)
if a=0 then
exit do
else
s=left(s,a-1)+r+mid(s,a+lw)
end if
a=lr+a-1
loop
end sub
sub replaceAny(byref s as string,byval w as string, byval r as string)
'=====================================================================
'
dim as sys a,b,c,i,j,lw,lr,ls
dim as string ch
'
lw=len(w) : if lw=0 then exit sub
lr=len(r)
ls=len(s)
i=1
do
if i>lw then exit do
b=asc(w,i)
ch=mid(r,i,1)
j=1
do
if j>ls then exit do
a=asc(s,j)
if a=b then mid(s,j)=ch
j+=1
loop
i+=1
loop
end sub
'TESTS
====
s="abcdefabcdef"
replace s,"abc","ABC"
print s 'ABCdefABCdef'
replaceAny s,"fed","FED"
print s 'ABCDEFABCDEF'