*process or(!) source xref attributes; sit: Proc Options(main); /********************************************************************* * Test string replacement * 02.08.2013 Walter Pachl *********************************************************************/ Dcl s Char(50) Var Init('Mary had a &X lamb. It is &X'); Put Edit(repl(s,'little','&X'))(Skip,A); repl: Proc(str,new,old) Returns(Char(50) Var); /********************************************************************* * ooREXX has CHANGESTR(old,str,new[,count]) * repl follows, however, the translate "philosophy" * translate(str,new,old) when old and new are just a character each * and replaces all occurrences of old in str by new *********************************************************************/ Dcl str Char(*) Var; Dcl (new,old) Char(*); Dcl (res,tmp) Char(50) Var init(''); Dcl p Bin Fixed(31); tmp=str; /* copy the input string */ Do Until(p=0); p=index(tmp,old); /* position of old in tmp */ If p>0 Then Do; /* found */ res=res!!left(tmp,p-1)!!new; /* append new to current result*/ tmp=substr(tmp,p+length(old)); /* prepare rest of input */ End; End; res=res!!tmp; /* final append */ Return(res); End; End;