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,851 questions

51,772 answers

573 users

How to check if a string is blank (empty, nil, or contains only whitespace) in Pascal

1 Answer

0 votes
program CheckBlankOrEmpty;

function IsBlankOrEmpty(str: PChar): Boolean;
var
  i: Integer;
begin
  // Check for NULL pointer
  if str = nil then
    Exit(True);

  // Iterate through the string to check for non-whitespace characters
  i := 0;
  while str[i] <> #0 do
  begin
    if not (str[i] in [' ', #9, #10, #13]) then  // Space, Tab, Line Feed, Carriage Return
      Exit(False);
    Inc(i);
  end;

  Exit(True);
end;

var
  test1, test2, test3, test4: PChar;
begin
  test1 := nil;         // NULL string pointer
  test2 := '';          // Empty string
  test3 := '   ';       // Whitespace only
  test4 := 'abc';       // Non-empty string

  WriteLn('Test1: ', IsBlankOrEmpty(test1)); 
  WriteLn('Test2: ', IsBlankOrEmpty(test2)); 
  WriteLn('Test3: ', IsBlankOrEmpty(test3)); 
  WriteLn('Test4: ', IsBlankOrEmpty(test4)); 
end.


   
     
(*
run:

Test1: TRUE
Test2: TRUE
Test3: TRUE
Test4: FALSE
     
*)

 



answered Jun 7, 2025 by avibootz
...