[VB.NET]関係演算子を使って文字列の比較サンプル

2021年11月29日

書式
Dim 変数文字列1 As String =値1
Dim 変数文字列2 As String =値2
変数文字列1 > 変数文字列2
関係演算子を用いて文字列同士の大小関係を比較します

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Public Sub Main()
Dim strA As String = "study"
Dim strB As String = "skill"
If strA < strB Then
Console.WriteLine("strA < strB 11")
ElseIf strA > strB Then
Console.WriteLine("strA > strB 22")
Else
Console.WriteLine("strA = strB 33")
End If
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() Dim strA As String = "study" Dim strB As String = "skill" If strA < strB Then Console.WriteLine("strA < strB 11") ElseIf strA > strB Then Console.WriteLine("strA > strB 22") Else Console.WriteLine("strA = strB 33") End If Console.ReadKey() End Sub End Module
Module Module1

    Public Sub Main()

        Dim strA As String = "study"
        Dim strB As String = "skill"

        If strA < strB Then
            Console.WriteLine("strA < strB 11")
        ElseIf strA > strB Then
            Console.WriteLine("strA > strB 22")
        Else
            Console.WriteLine("strA = strB 33")
        End If
        Console.ReadKey()
    End Sub

End Module

実行結果
strA > strB 22

VB.net

Posted by arkgame