Newsgroups: comp.lang.pascal Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!ukma!fehr From: fehr@ms.uky.edu (Jeff Davis) Subject: Substitution function Message-ID: <1991Apr25.142222.11906@ms.uky.edu> Organization: Aqueous,Calcareous,and Rhythmic Date: Thu, 25 Apr 1991 14:22:22 GMT Lines: 37 I saw a request for a substitution routine. This is a generalized routine that I use all the time. I'm sure there are better algorithms out there, but this seems to work. Overflows are simply truncated by Turbo. function simp(needle,haystack,sub:string):string; var i,j : integer; a,b : string; begin simp:=haystack; if pos(needle,haystack)=0 then exit; j:=length(needle); b:=''; i:=1; while i <= length(haystack) do begin a:=copy(haystack,i,j); if a=needle then begin b:=b+sub; inc(i,j); end else begin b:=b+haystack[i]; inc(i,1); end; end; simp:=b; end; -- davis@keats.ca.uky.edu Is this a long trip or a short trip?