6 ways to check for String Equality in VB.Net




Imports System.Text

Private str1 As String
Private str2 As String
Private str3 As String
Private pos1 As Boolean
Private pos2 As Integer


  1. pos1 = str1 = str2
  2. pos1 = String.Equals(str1, str2)
  3. pos2 = String.Compare(str1, str2)
    str3 = If(pos2 = 0, "True", "False")
  4. pos2 = String.CompareOrdinal(str1, str2)
    str3 = If(pos2 = 0, "True", "False")
  5. pos2 = str1.CompareTo(str2)
    str3 = If(pos2 = 0, "True", "False")
  6. pos2 = StrComp(str1, str2)
    str3 = If(pos2 = 0, "True", "False")