Export (0) Print
Expand All

String.IsNullOrWhiteSpace Method

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

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

'Declaration
Public Shared Function IsNullOrWhiteSpace ( _
	value As String _
) As Boolean

Parameters

value
Type: System.String
The string to test.

Return Value

Type: System.Boolean
true if the value parameter is Nothing 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) 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.

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


Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      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
         outputBlock.Text &= String.IsNullOrWhiteSpace(value) & vbCrLf
      Next
   End Sub
End Module
' The example displays the following output:
'       True
'       True
'       False
'       True
'       True
'       True


Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft