String.IsNullOrEmpty Method

Updated: January 2011

Indicates whether the specified string is Nothing or an Empty string.

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

'Declaration
Public Shared Function IsNullOrEmpty ( _
	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 an empty string (""); otherwise, false.

IsNullOrEmpty is a convenience method that enables you to simultaneously test whether a String is Nothing or its value is Empty. It is equivalent to the following code:


result = s Is Nothing OrElse s = String.Empty


The following code example determines whether each of three strings has a value, is an empty string or is Nothing.


Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim s1 As String = "abcd"
      Dim s2 As String = ""
      Dim s3 As String = Nothing

      outputBlock.Text += String.Format("String s1 {0}.", Test(s1)) & vbCrLf
      outputBlock.Text += String.Format("String s2 {0}.", Test(s2)) & vbCrLf
      outputBlock.Text += String.Format("String s3 {0}.", Test(s3)) & vbCrLf
   End Sub

   Public Shared Function Test(ByVal s As String) As String
      If String.IsNullOrEmpty(s) Then
         Return "is null or empty"
      Else
         Return String.Format("(""{0}"") is not null or empty", s)
      End If
   End Function 
End Class
' The example displays the following output:
'       String s1 ("abcd") is not null or empty.
'       String s2 is null or empty.
'       String s3 is null or empty.


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

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

Date

History

Reason

January 2011

Expanded the Remarks section.

Customer feedback.

Community Additions

ADD
Show: