希望这应该是一个容易的问题.在
java中,我认为是compareTo().
如何比较2个字符串变量来确定它们是否相同?
即:
If (string1 = string2 And string3 = string4) Then 'perform operation Else 'perform another operation End If
我建议使用
String.Compare方法.使用该方法,您还可以控制是否使其执行区分大小写的比较.
原文链接:https://www.f2er.com/vb/255655.html样品:
Dim str1 As String = "String one" Dim str2 As String = str1 Dim str3 As String = "String three" Dim str4 As String = str3 If String.Compare(str1,str2) = 0 And String.Compare(str3,str4) = 0 Then MessageBox.Show("str1 = str2 And str3 = str4") Else MessageBox.Show("Else") End If
编辑:如果要执行不区分大小写的搜索,可以使用StringComparison参数:
If String.Compare(str1,str2,StringComparison.InvariantCultureIgnoreCase) = 0 And String.Compare(str3,str4,StringComparison.InvariantCultureIgnoreCase) = 0 Then