Latest web development tutorials

VBScript StrComp function

VBScript Reference Complete VBScript Reference

StrComp function compares two strings and returns a value representative of the comparison result.

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)

grammar

StrComp(string1,string2[,compare])

参数 描述
string1 必需。字符串表达式。
string2 必需。字符串表达式。
compare 可选。规定要使用的字符串比较类型。默认是 0。

可采用下列的值:

  • 0 = vbBinaryCompare - 执行二进制比较
  • 1 = vbTextCompare - 执行文本比较

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 Reference Complete VBScript Reference