Indicates whether a specified string is
Assembly: mscorlib (in mscorlib.dll)
Public Shared Function IsNullOrWhiteSpace ( _
value As String _
) As Booleanpublic static bool IsNullOrWhiteSpace(
string value
)public:
static bool IsNullOrWhiteSpace(
String^ value
)static member IsNullOrWhiteSpace :
value:string -> bool
Parameters
- value
- Type: System
. . :: . String
The string to test.
Return Value
Type: Systemtrue if the value parameter is
IsNullOrWhiteSpace is a convenience method that is similar to the following code, except that it offers superior performance:
Return String.IsNullOrEmpty(value) OrElse value.Trim().Length = 0
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
The following example creates a string array, and then passes each element of the array to the IsNullOrWhiteSpace method.
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
Console.WriteLine(String.IsNullOrWhiteSpace(value))
Next
End Sub
End Module
' The example displays the following output:
' True
' True
' False
' True
' True
' True
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)
Console.WriteLine(String.IsNullOrWhiteSpace(value));
}
}
// The example displays the following output:
// True
// True
// False
// True
// True
// True
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.