本文整理汇总了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