Strings Delphi

Function String_Replace(
OldSubString : String;//atilacak metin
NewSubString : String;//atilanin yerine konacak metin
SourceString : String): String;//üzerinde dgisiklik
//yapilacak metin
Var
P : Integer;
S : String;
R : String;
LOld : Integer;
LNew : Integer;
Begin
S := SourceString;
R := '';
LOld := Length(OldSubString);
LNew := Length(NewSubString);
Result := S;
If OldSubString = '' Then Exit;
If SourceString = '' Then Exit;
P := Pos(OldSubString,S);
If P = 0 Then
Begin
R := S;
End
Else
Begin
While P <> 0 Do
Begin
Delete(S,P,LOld);
R := R + Copy(S,1,P-1)+NewSubString;
S := Copy(S,P,Length(S)-(P-1));
P := Pos(OldSubString,S);
If P = 0 Then R := R + S;
End;
End;
Result := R;
End;