VBScript中InStr函数的用法

InStr([start, ]str1, str2[, compare])

[用途]:返回str2在str1中的位置。匹配成功时,返回值最小值为1,未匹配到时返回0。

[参数说明]:

  start:在str1中开始匹配的位置,1表示从头开始,不能为0或更小值。 可选,默认为1。

  str1:长字符串

  str2:匹配关键字

  compare:匹配方式,取值为0或1。0表示执行二进制匹配。1表示执行文本匹配,即,忽略大小写。可选,默认为0。如果已指定"compare",则必须要有”start“参数。

[Sample]

  Msgbox Instr("HelloWorld","Hello") ->返回1

  Msgbox Instr("HelloWorld","world") ->返回0,这说明"compare"默认为0。

  Msgbox Instr(1, "HelloWorld","world", 1) ->返回6 ,这说明"compare"为1时可忽略大小写。

  Msgbox Instr("HelloWorld","world", 1) ->出错,这说明如果已指定"compare",则必须要有”start“参数。

原文地址:https://www.cnblogs.com/pzy4447/p/3315597.html