「VB.NET」文字列が空文字またはNullの判定サンプル
書式
String.IsNullOrEmpty(文字列)
使用例
Module Module1
Sub Main()
Dim strA As String = ""
Dim strB As String = "study"
Dim strC As String = Nothing
'IsNullOrEmptyで変数Aを判定
Dim resA As Boolean = (String.IsNullOrEmpty(strA))
'IsNullOrEmptyで変数Bを判定
Dim resB As Boolean = (String.IsNullOrEmpty(strB))
'IsNullOrEmptyで変数Cを判定
Dim resC As Boolean = (String.IsNullOrEmpty(strC))
Console.WriteLine(resA)
Console.WriteLine(resB)
Console.WriteLine(resC)
Console.ReadKey()
End Sub
End Module
Module Module1
Sub Main()
Dim strA As String = ""
Dim strB As String = "study"
Dim strC As String = Nothing
'IsNullOrEmptyで変数Aを判定
Dim resA As Boolean = (String.IsNullOrEmpty(strA))
'IsNullOrEmptyで変数Bを判定
Dim resB As Boolean = (String.IsNullOrEmpty(strB))
'IsNullOrEmptyで変数Cを判定
Dim resC As Boolean = (String.IsNullOrEmpty(strC))
Console.WriteLine(resA)
Console.WriteLine(resB)
Console.WriteLine(resC)
Console.ReadKey()
End Sub
End Module
Module Module1 Sub Main() Dim strA As String = "" Dim strB As String = "study" Dim strC As String = Nothing 'IsNullOrEmptyで変数Aを判定 Dim resA As Boolean = (String.IsNullOrEmpty(strA)) 'IsNullOrEmptyで変数Bを判定 Dim resB As Boolean = (String.IsNullOrEmpty(strB)) 'IsNullOrEmptyで変数Cを判定 Dim resC As Boolean = (String.IsNullOrEmpty(strC)) Console.WriteLine(resA) Console.WriteLine(resB) Console.WriteLine(resC) Console.ReadKey() End Sub End Module
実行結果
True
False
True