「VB.NET」IsNullOrEmptyで空文字またはNullの判定サンプル

2021年11月29日

書式
String.IsNullOrEmpty(文字列)
StringクラスのIsNullOrEmptyメソッドを使用して、文字列が空文字かNullのどちらかであることを判定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Public Sub Main()
'空文字
Dim strA As String = ""
Dim strB As String = "study"
'Null
Dim strC As String = Nothing
Console.WriteLine("空文字またはNullの判定結果")
Console.WriteLine(String.IsNullOrEmpty(strA))
Console.WriteLine(String.IsNullOrEmpty(strB))
Console.WriteLine(String.IsNullOrEmpty(strC))
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() '空文字 Dim strA As String = "" Dim strB As String = "study" 'Null Dim strC As String = Nothing Console.WriteLine("空文字またはNullの判定結果") Console.WriteLine(String.IsNullOrEmpty(strA)) Console.WriteLine(String.IsNullOrEmpty(strB)) Console.WriteLine(String.IsNullOrEmpty(strC)) Console.ReadKey() End Sub End Module
Module Module1

    Public Sub Main()

        '空文字
        Dim strA As String = ""
        Dim strB As String = "study"
        'Null
        Dim strC As String = Nothing

        Console.WriteLine("空文字またはNullの判定結果")
        Console.WriteLine(String.IsNullOrEmpty(strA))
        Console.WriteLine(String.IsNullOrEmpty(strB))
        Console.WriteLine(String.IsNullOrEmpty(strC))

        Console.ReadKey()
    End Sub

End Module

実行結果
空文字またはNullの判定結果
True
False
True

VB.net

Posted by arkgame