+92 332 4229 857 99ProjectIdeas@Gmail.com

String.Compare function (Vb.net)


String Compare function
String.Compare() function is used to compare two strings. It returns 0 when both the strings to be compared are equal. It returns -1 when the first string is smaller than the second string. And it returns +1 when the first string is larger than the second string.
System.string is the library for this compare function.
 
Example1
Dim str1 As String = "SAAD"
Dim str2 As String = "SAAD"
MsgBox(String.Compare(str1, str2))
Result
The result of this comparison will be 0 because both the strings are equal.

Example2
Dim str1 As String = "SAAD"
Dim str2 As String = "SAAED"
MsgBox(String.Compare(str1, str2))
Result 
The result of this comparison will be -1 because first string is smaller than the second one.

Example3
Dim str1 As String = "SAAED"
Dim str2 As String = "SAAD"
MsgBox(String.Compare(str1, str2))
Result 
The result of this comparison will be +1 because first string is greater than the second one.


Related articles

0 comments: