VBScript » Functions » StrComp

Syntax:
StrComp(String1, String2, Compare)
String1
The String1 argument is the first of two strings to compare.
String2
The String2 argument is the second of two strings to compare.
Compare
The optional Compare argument can be used to set whether the comparison is case sensitive (upper versus lower), or not. You must only use a constant or value from the Comparison Constants table.

The StrComp function compares two strings to see if they are the same. You can have the comparison be sensitive, or not, to the case (upper versus lower) of the characters in the two strings. The default is to be case sensitive (binary comparison).

If the strings are the same, the output is zero. If the strings are different, the output will be a 1 or -1 depending on the order of the strings.

Comparison Constants

CONSTANT VALUE DESCRIPTION
VBBinaryCompare 0 Binary comparison

(case sensitive)
VBTextCompare 1 Text Comparison

(case insensitive)

Examples

Code:
<% =StrComp("Mountains of the Moon", "Mountains of the Moon") %>
Output:
0
Language(s): VBScript
Code:
<% =StrComp("Mountains of the Moon", "Red sails at sunset") %>
Output:
-1
Language(s): VBScript
Code:
<% =StrComp("Mountains of the Moon", "mountains of the moon", 0) %>
Output:
-1
Language(s): VBScript
Code:
<% =StrComp("Mountains of the Moon", "mountains of the moon", 1) %>
Output:
0
Language(s): VBScript
Code:
<% =StrComp("RED", "red", VBTextCompare) %>
Output:
0
Language(s): VBScript