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