介绍一下InstrRev函数
InstrRev函数:从字符串的最后一个字符搜索起,向前面逐个搜索前面字符串,返回字符在字符串当中的第几位。
举例来说明其应用:
ASP/Visual Basic代码
- <%
- Dim strTXT,pos
- strTXT=www.baidu.com
- pos=instrRev(strTXT,".")
- Response.Write pos
- %>
InstrRev函数搜索的起始是倒序,倒着搜索到com前的那个“.”。返回这个点在字符串中的位置,从0开始计数(类似数组),这个点为第12位,所以返回的结果将是11。
通过此原理,我们不光可以取得ASP页面的文件名,还可以获取域名后缀名等信息,应用还是比较广泛的。
下面这几句代码就是实现获取当前文件名(放到ASP页面里,就能打印出当前文件名):
ASP/Visual Basic代码
- Dim strURL,intPos,intStrLen,strFileName
- strURL = Request.Servervariables("url")
- intPos = InstrRev(strURL,"/")
- intStrLen = len(strURL)
- strFileName = Right(strURL,intStrLen-intPos)
- Response.Write strFileName
如果希望函数来获取,调用如下getFileName()函数即可实现:
ASP/Visual Basic代码
- Function getFileName()
- Dim strURL,intPos,intStrLen,strFileName
- strURL = Request.Servervariables("url")
- intPos = InstrRev(strURL,"/")
- intStrLen = len(strURL)
- strFileName = Right(strURL,intStrLen-intPos)
- getFileName = strFileName
- End Function
留言