RosettaCodeData/Task/Strip-control-codes-and-extended-characters-from-a-string/Pascal/strip-control-codes-and-extended-characters-from-a-string.pascal
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

26 lines
659 B
Text

program StripCharacters(output);
function Strip (s: string; control, extended: boolean): string;
var
index: integer;
begin
Strip := '';
for index:= 1 to length(s) do
if not ((control and (ord(s[index]) <= 32)) or (extended and (ord(s[index]) > 127))) then
Strip := Strip + s[index];
end;
var
test: string;
i: integer;
begin
setlength(test, 40);
randomize;
for i := 1 to length(test) do
test[i] := char(1 + random(255));
writeln ('Original: ', test);
writeln ('No CNTL: ', Strip(test, true, false));
writeln ('No extnd: ', Strip(test, false, true));
writeln ('ASCII: ', Strip(test, true, true));
end.