Late to the party... Here is my version...
say chgstr('xexexe','qq','xe')
say chgstr('xexexe','ae','k')
say chgstr('xexexe','ae','e')
say chgstr('xexexe','Q','xexex')
say chgstr('xexe xe xe xexex','ll','e')
say chgstr('xexe xe xe xexex','f','xe')
say chgstr('aaaa','1','a')
say chgstr('zzzz','26','z')
say chgstr('zzzz','-AAAAA-','z')
say chgstr('error','xx')
say chgstr('JOHN JACOB GEORGE SCHMIDT','JINGLEHEIMER','GEORGE')
say chgstr('JOHN JACOB GEORGE SCHMIDT','*',' ')
say chgstr('the quick brown fox','SLOW RED','quick brown')
exit 0
chgstr: procedure
if arg() <> 3 then
return 'chgstr: missing args, must have string, new and old'
string = arg(1)
new = arg(2)
old = arg(3)
lnew = length(new)
lold = length(old)
x = 1
do forever
if pos(old,string,x) = 0 then return string
x = pos(old,string,x)
string = insert(new,delstr(string,x,lold),x-1,lnew)
x = x + length(new)
end
Rob