Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

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, #@ ! ^&Programming (*).';
  
    s := RemoveNonAlphaNum(s);
  
    WriteLn(s);
end.



(*
run:

PascalProgramming

*)

 



answered Jan 29, 2025 by avibootz
edited Jan 29, 2025 by avibootz
...