马桶盖价格:VBSCRIPT的函数问题????高手进!!

来源:百度文库 编辑:高考问答 时间:2024/05/03 10:23:41
Function GetContent(str,start,last,n)
If Instr(lcase(str),lcase(start))>0 then
select case n
case 0 '左右都截取(都取前面)(去处关键字)
GetContent=Right(str,Len(str)-Instr(lcase(str),lcase(start))-Len(start)+1)
GetContent=Left(GetContent,Instr(lcase(GetContent),lcase(last))-1)
case 1 '左右都截取(都取前面)(保留关键字)
GetContent=Right(str,Len(str)-Instr(lcase(str),lcase(start))+1)
GetContent=Left(GetContent,Instr(lcase(GetContent),lcase(last))+Len(last)-1)
case 2 '只往右截取(取前面的)(去除关键字)
GetContent=Right(str,Len(str)-Instr(lcase(str),lcase(start))-Len(start)+1)
end select
Else
GetContent=""
End if

在这段函数里有这么一句话
GetContent=Right(str,Len(str)-Instr(lcase(str),lcase(start))-Len(start)+1)
谁能大概的给我分析一下,最好有实例化的讲解.

LCase 是将字符串中英文字母变为小写,故在此问题中可不理会。
则变成:
GetContent=Right(str,Len(str)-Instr(str,start)-Len(start)+1)

若str="ABCDEFGH",start="DE",
则GetContent="FGH".

Instr(str,start),在str里寻找start,返回4
Len(start),返回start长度,即返回2.所以Len(str)返回8
Len(str)-Instr(str,start)-Len(start)+1:
8-4-2+1=3
Right(str,Len(str)-Instr(str,start)-Len(start)+1):
在str中,取右三位,即返回"FGH"

总结:这条语句,是用于截取字符串中关键字后边(不包括关键字)的子字符串的。
整个函数,就是用来截取字符串中关键字前(后),包括(不包括)关键字的子字符串的。