日期:2009-12-26  浏览次数:20890 次

在制作一个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