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

2021年10月6日

書式
String.IsNullOrEmpty(文字列)

使用例

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

VB.net

Posted by arkgame