function ReplaceSpaces(s: string): string; var i: Integer; LastWasPlus: Boolean; begin result := StringReplace(s, ' ', '+', [rfReplaceAll]); i := 1; LastWasPlus := false; while (i < Length(result)) do begin If result[i] = '+' then begin If LastWasPlus = true then delete(result, i, 1) else begin LastWasPlus := true; inc(i); end; end else begin LastWasPlus := false; inc(i); end; end; end; // Use: Edit1.Text := ReplaceSpaces(Edit1.Text);