「VB.NET」String変数がブランクかどうかチェックする

2022年1月14日

書式
変数名 Is Nothing
String.IsNullOrEmpty(変数名)

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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

VB.net

Posted by arkgame