How to remove all non-alphanumeric characters from a string in Pascal

1 Answer

0 votes
program RemoveNonAlphanumericProgram;
 
function IsAlphaNum(ch: Char): Boolean;
begin
    IsAlphaNum := (ch in ['A'..'Z', 'a'..'z', '0'..'9']);
end;
 
function RemoveNonAlphaNum(const s: string): string;
var
    i: Integer;
    resultString: string;
begin
    resultString := '';
    for i := 1 to Length(s) do
    begin
        if IsAlphaNum(s[i]) then
            resultString := resultString + s[i];
    end;
    RemoveNonAlphaNum := resultString;
end;
 
var
    s: string;
 
begin
    s := 'Pascal, #@ ! 901^&Programming (*).';
   
    s := RemoveNonAlphaNum(s);
   
    WriteLn(s);
end.
 
 
 
{
run:
 
Pascal901Programming
 
}

 



answered Jan 29, 2025 by avibootz
edited 1 day ago by avibootz

Related questions

...