ASP取得地址URL中的頂級網域名稱的函數

來源:互聯網
上載者:User
ASP取得地址欄中URL網址中的頂級網域名稱函數,非正則,非常實用,親自調試好用。

在製作一個DLL組件中,由於DLL裡不方便調用正則函數,所以,製作了一個不需要正則的取得跟網域名稱的函數,貢獻給大家!

以下內容為程式碼Private Function durl(url)
Dim domext, s1, s2, re, matches, arrdom, dd
domext = "comnetorgcnlaccinfohkbizmemobinametvasiakrdeorg.cnco.krcom.cnnet.cngov.cn"
arrdom = Split(domext, "")
durl = "": url = LCase(url)
If url = "" Or Len(url) = 0 Then Exit Function
url = Replace(Replace(url, "http://", ""), "https://", "")
s1 = InStr(url, ":") - 1 '過濾掉連接埠
If s1 < 0 Then s1 = InStr(url, "/") - 1 '過濾掉/後面的字元
If s1 > 0 Then url = Left(url, s1)
s2 = Split(url, ".")(UBound(Split(url, ".")))
If InStr(domext, s2) = 0 Then
    durl = url
Else
    For dd = 0 To UBound(arrdom)
        If InStr(url, "." & arrdom(dd)) > 0 Then
            durl = Replace(url, "." & arrdom(dd) & "", "")
            If InStr(durl, ".") = 0 Then
            durl = url
            Else
            durl = Split(durl, ".")(UBound(Split(durl, "."))) & "." & arrdom(dd)
            End If
        End If
    Next
End If
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.