How to check if a string has only whitespace or is empty in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string str1 = "c#";

        string str2 = "     ";
        string str3 = "";

        Console.WriteLine(string.IsNullOrWhiteSpace(str1));
        Console.WriteLine(string.IsNullOrWhiteSpace(str2));     
        Console.WriteLine(string.IsNullOrWhiteSpace(str3));     
    }
}
  
  
  
/*
run:
  
False
True
True
  
*/

 



answered Aug 3, 2022 by avibootz
...