Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.IsNullOrWhiteSpace Method

July 28, 2014

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static bool IsNullOrWhiteSpace(
	string value
)

Parameters

value
Type: System.String
The string to test.

Return Value

Type: System.Boolean
true if the value parameter is null or String.Empty, or if value consists exclusively of white-space characters.

IsNullOrWhiteSpace is a convenience method that is equivalent to the following code, except that it offers superior performance:


return String.IsNullOrEmpty(value) || value.Trim().Length == 0;


White-space characters are defined by the Unicode standard. The IsNullOrWhiteSpace method interprets any character that returns a value of true when it is passed to the Char.IsWhiteSpace method as a white-space character.

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


using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      string[] values = { null, String.Empty, "ABCDE", 
                          new String(' ', 20), "  \t   ", 
                          new String('\u2000', 10) };
      foreach (string value in values)
         outputBlock.Text += String.IsNullOrWhiteSpace(value) + "\n";
   }
}
// The example displays the following output:
//       True
//       True
//       False
//       True
//       True
//       True


Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2014 Microsoft