Forum > General

my AnsiReplaceStr

(1/1)

yellowelise:
Hi I make my version of AnsiReplaceStr
the version I found in internet crash in replace char with same char
es.
 AnsiReplaceStr(edit1.text, '''', '''''');
this "improved" version works well  :)

function TFrmMain.AnsiReplaceStr(s,src,dest: string): string;
var l,p: integer;
r, s_head, s_end : string;
begin
s_head := '';
s_end := '';

p:=pos(src,s);
if p = 0 then
 begin
  r := s;
 end
 else
  begin

  l:=length(src);
  repeat
    p:=pos(src,s);
    if p>0 then
     begin
      if s_head <> '' then
       s_head := s_head + dest + copy(s,1,p-1)
      else
       s_head := s_head + copy(s,1,p-1);

      s_end :=copy(s,p+length(src),length(s));
      r:=s_head + dest + s_end;
      s := s_end;
     end;
  until p=0;


  end;
  result:=r;
end;                   

sorry fo my poor english

Navigation

[0] Message Index

Go to full version