本文整理匯總了VB.NET中System.String.IsNullOrEmpty方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET String.IsNullOrEmpty方法的具體用法?VB.NET String.IsNullOrEmpty怎麽用?VB.NET String.IsNullOrEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.String
的用法示例。
在下文中一共展示了String.IsNullOrEmpty方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Sample
Class Sample
Public Shared Sub Main()
Dim s1 As String = "abcd"
Dim s2 As String = ""
Dim s3 As String = Nothing
Console.WriteLine("String s1 {0}.", Test(s1))
Console.WriteLine("String s2 {0}.", Test(s2))
Console.WriteLine("String s3 {0}.", Test(s3))
End Sub
Public Shared Function Test(s As String) As String
If String.IsNullOrEmpty(s) Then
Return "is null or empty"
Else
Return String.Format("(""{0}"") is neither null nor empty", s)
End If
End Function
End Class
輸出:
String s1 ("abcd") is neither null nor empty. String s2 is null or empty. String s3 is null or empty.
示例2: Main
Module Example
Public Sub Main()
Dim s As String
Console.WriteLine("The value of the string is '{0}'", s)
Try
Console.WriteLine("String length is {0}", s.Length)
Catch e As NullReferenceException
Console.WriteLine(e.Message)
End Try
End Sub
End Module
輸出:
The value of the string is '' Object reference not set to an instance of an object.
示例3: FileSystem
Option Strict On
Imports System.Collections.ObjectModel
Imports System.IO
Public Module FileSystem
Public Sub Main()
Dim dirPath As String = "c:\\"
If String.IsNullOrEmpty(dirPath) Then Exit Sub
If Not Directory.Exists(dirPath) Then Exit Sub
Dim dirs As ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetDirectories(dirPath)
For Each dir As String In dirs
Dim dirInfo As DirectoryInfo = New DirectoryInfo(dir)
Console.WriteLine("{0} : Created {1}", dirinfo.Name,dirInfo.CreationTime)
Next
End Sub
End Module