Name
StrComp Function
Syntax
StrComp(string1,string2[,compare])
string1Use: Required
Data Type: String
Any string expression.
string2Use: Required
Data Type: String
Any string expression.
compareUse: Optional
Data Type: Integer constant
The type of string comparison to perform.
Return Value
An Integer.
Description
Determines whether two strings are equal and which of two strings is greater.
Rules at a Glance
The following intrinsic constants are available as the settings for
compare:
Constant | Value | Comparison to perform |
| 0 | Binary (default) |
| 1 | Textual |
If
compareisn’t specified, its value defaults tovbBinaryCompare. In other words, the comparison ofstring1andstring2is case-sensitive.This table describes the possible return values from the StrComp function:
Scenario | Return value |
| -1 |
| 0 |
| 1 |
| |
Programming Tips and Gotchas
If you just need to know whether
string1is greater thanstring2(or vice versa), couldn’t you simply use the<or>comparison operators? When you’re dealing with strings of characters, VBScript sees each character as a number. Simply using the comparison operators therefore compares the numerical value of one string with the other. Take this scenario:Dim sString1 Dim sString2 sString1 = "hello world" sString2 = "HELLO WORLD"
Subjectively, because of the significance of uppercase letters in text, we’d probably say that
sString2is greater thansString1. But VBScript sees ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access