Advertisement
RadioNurshat

Replace All

Feb 3rd, 2021 (edited)
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.46 KB | None | 0 0
  1. function replaceAll(haystack: string; needle:string; cod:string):string;
  2. begin
  3.   var s:string = haystack;
  4.   var proc:string = '';
  5.   var p,len:integer;
  6.   len:=length(needle);
  7.   while(length(s)>0) do begin
  8.     p:=s.IndexOf(needle);
  9.     if (p=0) then begin proc+=s; break; end;
  10.     if (p>1) then proc+=copy(s,1,p-1);
  11.     proc+=cod;
  12.     if (p+len)>length(s) then
  13.       s:='' else
  14.       s:=copy(s,p+len,length(s)-p-len);
  15.   end;
  16.   replaceAll:=proc;
  17. end;
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement