Remove All Whitespace in Pascal

Published on 21 July 2025 (Updated: 21 July 2025)

Welcome to the Remove All Whitespace in Pascal page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

program RemoveAllWhitespace;

{$mode objfpc}{$H+}

uses
   SysUtils;

procedure ShowUsage;
begin
   Writeln('Usage: please provide a string');
   Halt(1);
end;

function RemoveWhitespace(const S: string): string;
var
   builder: TStringBuilder;
   ch: char;
begin
   builder := TStringBuilder.Create;
   try
      for ch in S do
         case ch of
            ' ', #9, #10, #13: Continue;
            else
               builder.Append(ch);
         end;

      Result := builder.ToString;
   finally
      builder.Free;
   end;
end;

var
   Input: string;
   Output: string;
begin
   if ParamCount <> 1 then
      ShowUsage;

   Input := ParamStr(1);
   if Input = '' then
      ShowUsage;

   Output := RemoveWhitespace(Input);
   Writeln(Output);
end.

Remove All Whitespace in Pascal was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.