「VB.NET」String変数がブランクかどうかチェックする
書式
変数名 Is Nothing
String.IsNullOrEmpty(変数名)
使用例
Module Module1
Public Sub Main()
Dim kk As String = Nothing
Dim mm As String = ""
'Nothingだけ判断
Dim resA As Boolean = (kk Is Nothing)
'Nothingと空文字("")だけ判断
Dim resB As Boolean = String.IsNullOrEmpty(mm)
Console.WriteLine("結果1: " & resA)
Console.WriteLine("結果2: " & resB)
Console.ReadKey()
End Sub
End Module
Module Module1
Public Sub Main()
Dim kk As String = Nothing
Dim mm As String = ""
'Nothingだけ判断
Dim resA As Boolean = (kk Is Nothing)
'Nothingと空文字("")だけ判断
Dim resB As Boolean = String.IsNullOrEmpty(mm)
Console.WriteLine("結果1: " & resA)
Console.WriteLine("結果2: " & resB)
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() Dim kk As String = Nothing Dim mm As String = "" 'Nothingだけ判断 Dim resA As Boolean = (kk Is Nothing) 'Nothingと空文字("")だけ判断 Dim resB As Boolean = String.IsNullOrEmpty(mm) Console.WriteLine("結果1: " & resA) Console.WriteLine("結果2: " & resB) Console.ReadKey() End Sub End Module
実行結果
結果1: True
結果2: True