一聚教程网:一个值得你收藏的教程网站

热门教程

asp 常用几个实例函数

时间:2022-06-29 14:27:03 编辑:袖梨 来源:一聚教程网

1、检查文件是否存在
用法示例:If CheckFile("aa.jpg") = True Then Response.Write "OK"

复制内容到剪贴板 程序代码
Function CheckFile(FileName)
   On Error Resume Next
  Dim FsoObj
  Set FsoObj = Server.CreateObject("Scripting.FileSystemObject")
  If Not FsoObj.FileExists(Server.MapPath(FileName)) Then
    CheckFile = False
    Exit Function
  End If
  CheckFile = True:Set FsoObj = Nothing
End Function

2、检测字符串出现次数

参数说明:TheChar="要检测的字符串",TheString="待检测的字符串"
用法示例:If CheckTheChar("a","about") = 1 Then Response.Write "OK"
复制内容到剪贴板 程序代码
Function CheckTheChar(TheChar,TheString)
  If InStr(TheString,TheChar) Then
    For n = 1 To Len(TheString)
      If Mid(TheString,n,Len(TheChar)) = TheChar Then
        CheckTheChar = CheckTheChar + 1
      End If
    Next
    CheckTheChar = CheckTheChar
  Else
    CheckTheChar = 0'"0次"
  End If
End Function

3、取完整的URL地址

复制内容到剪贴板 程序代码
Function GetUrl()
  Dim ScriptAddress, M_ItemUrl, M_item
  ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME")) '取得当前地址
  M_ItemUrl = ""
  If (Request.QueryString <> "") Then
    ScriptAddress =  ScriptAddress & "?"
    For Each M_item In Request.QueryString
      If InStr(page,M_Item)=0 Then
        M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&""))  & ""
      End If
    Next
  End If
  GetUrl = ScriptAddress & M_ItemUrl
End Function

热门栏目