Registriert seit: 24. Feb 2005
Ort: Schweiz/Thurgau
138 Beiträge
Delphi 2010 Professional
|
Re: An bestimmter Stelle eines Strings einen Wert setzen
29. Mai 2008, 16:38
Habe mir jetzt selber geholfen... Habe eine Funktion SetPiece geschrieben:
Vielleicht könnt Ihr diese auch mal gebrauchen...
Delphi-Quellcode:
function SetPiece(S: string; D: Char; i: Integer; ReplaceString: string): string;
var
Count, Position, EndPosition: Integer;
Stop: Boolean;
NewString: string;
begin
NewString := '';
Count := 1;
Stop := (Count >= i);
while not Stop do
begin
Position := Pos(D, S);
if Position > 0 then
begin
NewString := NewString + Copy(S, 1, Position);
Delete(S, 1, Position)
end
else
begin
S := '';
Stop := True;
end;
Count := Count + 1;
if Count = i then
Stop := True;
end;
EndPosition := Pos(D, S);
if EndPosition = 0 then
EndPosition := Length(S)
else
EndPosition := EndPosition - 1;
Result := Copy(S, 1, EndPosition);
Result := NewString + ReplaceString + Copy(S, Length(Result) + 1, Length(S))
end;
|
|
Zitat
|