comparing strings in vb

前端 未结 6 819
南方客
南方客 2021-01-17 08:06

Hopefully this should be an easy question. In java i think it\'s compareTo().

How do I compare 2 string variables to determine if they are the same?

6条回答
  •  太阳男子
    2021-01-17 08:41

    Dim MyString As String = "Hello World"
    Dim YourString As String = "Hello World"
    Console.WriteLine(String.Equals(MyString, YourString))
    

    returns a bool True. This comparison is case-sensitive.

    So in your example,

    if String.Equals(string1, string2) and String.Equals(string3, string4) then
      ' do something
    else
      ' do something else
    end if
    

提交回复
热议问题