如何把URL和邮件地址转换为超级链接? -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    作者: 字体:[增加 减小] 类型:转载

    Function InsertHyperlinks(inText)

    Dim objRegExp, strBuf

    Dim objMatches, objMatch

    Dim Value, ReplaceValue, iStart, iEnd

    strBuf = ""

    iStart = 1

    iEnd = 1

    Set bjRegExp = New RegExp

    objRegExp.Pattern = "\b(www|http|\S+@)\S+\b"

    ‘判断URLs和emails.

    objRegExp.IgnoreCase = True

    ‘设置大小写不敏感..

    objRegExp.Global = True

    ‘全局适用.

    Set bjMatches = objRegExp.Execute(inText)

    For Each objMatch in objMatches

    iEnd = objMatch.FirstIndex

    strBuf = strBuf & Mid(inText, iStart, iEnd-iStart+1)

    If InStr(1, objMatch.Value, "@") Then

    strBuf = strBuf & GetHref(objMatch.Value, "EMAIL", "_BLANK")

    Else

    strBuf = strBuf & GetHref(objMatch.Value, "WEB", "_BLANK")

    End If

    iStart = iEnd+objMatch.Length+1

    Next

    strBuf = strBuf & Mid(inText, iStart)

    InsertHyperlinks = strBuf

    End Function

    Function GetHref(url, urlType, Target)

    Dim strBuf

    strBuf = "

    If UCase(urlType) = "WEB" Then

    If LCase(Left(url, 3)) = "www" Then

    strBuf = "

    Target & """>" & url & ""

    Else

    strBuf = "

    Target & """>" & url & ""

    End If

    ElseIf UCase(urlType) = "EMAIL" Then

    strBuf = "

    Target & """>" & url & ""

    End If

    GetHref = strBuf

    End Function

   

   

    [1]

最新文章