asp 常用幾個執行個體函數

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.