StrComp() compares two strings and returns -1, 0 or 1 depending on their ordering/equality.
StrComp(string1, string2, comparetype)
Use vbBinaryCompare (0) for a binary comparison or vbTextCompare (1) for a textual comparison. Naming the constant is clearer than leaving an unexplained numeric value in application code.
Dim string1, string2
string1="Plus2net.com"
string2="plus2net.com"
Response.Write StrComp(string1, string2, vbBinaryCompare)
| string1 | string2 | compare | Result |
|---|---|---|---|
| Plus2net.com | plus2net.com | vbBinaryCompare | -1 |
| Plus2net.com | plus2net.com | vbTextCompare | 0 |
| Plus2net.com | Plus2net.com | vbBinaryCompare | 0 |
| plus2net.com | Plus2net.com | vbBinaryCompare | 1 |
If either argument is Null, the comparison result is Null. Choose binary or text comparison deliberately rather than assuming every comparison should ignore case.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.