Name
StrComp Function
Syntax
StrComp(string1,string2[,compare])
-
string1 Use: Required
Data Subtype: String
Any string expression.
-
string2 Use: Required
Data Subtype: String
Any string expression.
-
compare Use: Optional
Data Subtype: Integer constant
The type of string comparison to perform.
Return Value
A Variant of subtype 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
StrCompfunction:
|
Scenario |
Return Value |
|---|---|
|
|
-1 |
|
|
0 |
|
|
1 |
|
|
|
Programming Tips & Gotchas
If you just need to know if
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 ...
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