(>大于)运算符将按字母顺序或字符代码值顺序(取决于Option Compare设置)进行测试,而<>(不等于)运算符将测试是否相等。只要两个字符串完全不同, then<>将始终评估为True。 >只要运算符右侧的字符串按字母顺序或字符代码值位于第一个字符串之后,就会评估为真。所以:
Option Compare Text ' Compare strings alphabetically
...
Dim x As String = "Hello"
Dim y As String = "World"
If x <> y Then
' This block is executed because the strings are different
Else
' This block is skipped
End If
If x > y Then
' This block is skipped
Else
' This block is executed because "Hello" is less than "World" alphabetically
End If
但是,在您的问题中,您将一个空字符串变量(设置为Nothing)与一个空字符串进行比较。在这种情况下,比较运算符将 null 变量视为空字符串。因此,Nothing <> ""应该评估为,False因为运算符的两边都被认为是空字符串。空字符串或空字符串应始终被视为排序顺序中的第一个,因此Nothing > "Hello"应评估为,False因为空字符串位于其他所有内容之前。但是,Nothing > ""应该评估为,False因为它们都是相等的,因此既不在另一个之前也不在另一个之后。
为了回答你最后一个问题,"Test" > " "将测试字母 T 是在空格之前还是之后。如果Option Compare设置为Text,它将按字母顺序比较它们并应返回True(这最终取决于您的语言环境的字母排序)。如果Option Compare设置为Binary,它将根据它们的字符代码值进行比较。如果它们是 ASCII 字符串,则空格字符的值低于字母,例如 T,因此它也应该返回True.