diff --git a/archive/p/pascal/remove_all_whitespace.pas b/archive/p/pascal/remove_all_whitespace.pas new file mode 100644 index 000000000..81e44b393 --- /dev/null +++ b/archive/p/pascal/remove_all_whitespace.pas @@ -0,0 +1,47 @@ +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.