VBScript InStrRev 函数

定义和用法

InStrRev 函数可返回一个字符串在另一个字符串中首次出现的位置。搜索从字符串的末端开始,但是返回的位置是从字符串的起点开始计数的。

InStrRev 函数可返回下面的值:

  • 如果 string1 为 ""(零长度) - InStr 返回 0
  • 如果 string1 为 Null - InStr 返回 Null
  • 如果 string2 为 "" - InStr 返回 start
  • 如果 string2 为 Null - InStr 返回 Null
  • 如果 string2 没有找到 - InStr 返回 0
  • 如果在 string1 中找到 string2,InStr 返回找到匹配字符串的位置。
  • 如果 start > Len(string1) - InStr 返回 0

提示:请参阅 InStr 函数

语法

InStrRev(string1,string2[,start[,compare]])
参数 描述
start 可选的。规定每次搜索的起始位置。默认是搜索起始位置是第一个字符。如果已规定 compare 参数,则必须有此参数。
string1 必需的。需要被搜索的字符串。
string2 必需的。需搜索的字符串。
compare

必需的。规定要使用的字符串比较类型。默认是 0 。可采用下列值:

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

实例

例子 1

dim txt,pos
txt="This is a beautiful day!"
pos=InStrRev(txt,"his")
document.write(pos)

输出:

2

例子 2

dim txt,pos
txt="This is a beautiful day!"
'textual comparison
pos=InStrRev(txt,"B",-1,1)
document.write(pos)

输出:

11

例子 3

dim txt,pos
txt="This is a beautiful day!"
'binary comparison
pos=InStrRev(txt,"T")
document.write(pos)

输出:

1

例子 4

dim txt,pos
txt="This is a beautiful day!"
'binary comparison
pos=InStrRev(txt,"t")
document.write(pos)

输出:

15


http://www.vxiaotou.com