VBScript StrCompFunction


VBScript 参考手册Complete VBScript Reference Manual

The StrComp function compares two strings and returns a value representing the comparison result.

The StrComp function can return the following values:

  • -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
string1 Required. A string expression.
string2 Required. A string expression.
compare Optional. Specifies the type of string comparison to use. The default is 0.

Can take the following values:

  • 0 = vbBinaryCompare - Performs a binary comparison
  • 1 = vbTextCompare - Performs a text comparison

Example 1

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

Output:

0

Example 2

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

Output:

-1

Example 3

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

Output:

0


VBScript 参考手册Complete VBScript Reference Manual Other extensions