C# String IsNullOrWhiteSpace

Description

String IsNullOrWhiteSpace indicates whether a specified string is null, empty, or consists only of white-space characters.

Syntax

String.IsNullOrWhiteSpace has the following syntax.


public static bool IsNullOrWhiteSpace(
  string value
)

Parameters

String.IsNullOrWhiteSpace has the following parameters.

  • value - The string to test.

Returns

String.IsNullOrWhiteSpace method returns true if the value parameter is null or String.Empty, or if value consists exclusively of white-space characters.

Example

The following example creates a string array, and then passes each element of the array to the IsNullOrWhiteSpace method.


using System;//  www. j a v a  2s.c o  m

public class Example
{
   public static void Main()
   {
      string[] values = { null, String.Empty, "ABCDE", 
                          new String(' ', 20), "  \t   ", 
                          new String('\u2000', 10) };
      foreach (string value in values)
         Console.WriteLine(String.IsNullOrWhiteSpace(value));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version