// Using SysUtils.StringReplace with a loop
program RemoveMultipleSpaces;
{$mode objfpc}{$H+}
uses SysUtils;
function CollapseSpaces(S: string): string;
begin
repeat
S := StringReplace(S, ' ', ' ', [rfReplaceAll]);
until Pos(' ', S) = 0;
Result := S;
end;
begin
WriteLn(CollapseSpaces('Hello world this is Pascal'));
end.
(* run:
Hello world this is Pascal
*)