VBScript StrComp Function

Definition and Usage

The StrComp function can compare two strings and return a value representing the comparison result.

The StrComp function can return the following values:

  • -1 (if string1 < string2)
  • -1 (if string1 < string2)
  • 0 (if string1 = string2)
  • 1 (if string1 > string2)

Null (if string1 or string2 is Null)

Syntax
StrComp(string1,string2[,compare]) Parameters
Description string2
string1 string2
Required. String expression.

compare

Optional. Specifies the string comparison to use. Default is 0

  • Values available:
  • 0 = vbBinaryCompare - Perform binary comparison

1 = vbTextCompare - Perform text comparison

Instance

Example 1

Output:

0

Example 2

document.write(StrComp("VBScript","vbscript"))

Output:

-1

Example 3

document.write(StrComp("VBScript","vbscript",1))

Output:

0