String.IsNullOrWhiteSpace(String) String.IsNullOrWhiteSpace(String) String.IsNullOrWhiteSpace(String) String.IsNullOrWhiteSpace(String) Method


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

 static bool IsNullOrWhiteSpace(System::String ^ value);
public static bool IsNullOrWhiteSpace (string value);
static member IsNullOrWhiteSpace : string -> bool
Public Shared Function IsNullOrWhiteSpace (value As String) As Boolean
String String String String

The string to test.


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


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 Main()
      string[] values = { null, String.Empty, "ABCDE", 
                          new String(' ', 20), "  \t   ", 
                          new String('\u2000', 10) };
      foreach (string value in values)
// The example displays the following output:
//       True
//       True
//       False
//       True
//       True
//       True
Module Example
   Public Sub Main()
      Dim values() As String = { Nothing, String.Empty, "ABCDE", 
                                 New String(" "c, 20), "  " + vbTab + "   ", 
                                 New String(ChrW(&h2000), 10) }
      For Each value As String In values
   End Sub
End Module
' The example displays the following output:
'       True
'       True
'       False
'       True
'       True
'       True


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

return String.IsNullOrEmpty(value) || value.Trim().Length == 0;
Return String.IsNullOrEmpty(value) OrElse 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.

Applies to

See Also