String Equals function
String.Equals() function determines whether two strings have same value or not.
System.String is the library for this function.
Example1
Dim str1 As String = "SAAD"
Dim str2 As String = "SaaD"
MsgBox(String.Equals(str1, str2))
Result
It will return false because both the string do not have same value, the ascii codes of each string will be different due to capital and small letters.
Example2
Dim str1 As String = "SAAD"
Dim str2 As String = "SAAD"
MsgBox(String.Equals(str1, str2))
Result
It will return true because both the string have exactly same values.
Example3
Dim str1 As String = "SAAD"
Dim str2 As String = "SaaD"
MsgBox(String.Equals(str1.ToLower, str2.ToLower))
Result
It will return true because both the string now have exactly same values because both the strings are converted into lowercase letters.
Example4
Dim str1 As String = "SAAD"
Dim str2 As String = "SaaD"
MsgBox(String.Equals(str1.ToUpper, str2.ToUpper))
Result
It will return true because both the string now have exactly same values because both the strings are converted into uppercase letters.
Example5
Dim str1 As String = "SAAD"
Dim str2 As String = "SaaD"
MsgBox(String.Equals(str1, str2, StringComparison.InvariantCultureIgnoreCase))
Result
It will return true because due to StringComparison.InvariantCultureIgnoreCase parameter, Equals() function now only check the letters not the case.
Related articles
0 comments:
Post a Comment