Function InsertHyperlinks(inText)
Dim objRegExp, strBuf
Dim objMatches, objMatch
Dim Value, ReplaceValue, iStart, iEnd
strBuf = ""
iStart = 1
iEnd = 1
Set objRegExp = New RegExp
objRegExp.Pattern = "\b(www|http|\S+@)\S+\b"
' 判斷URLs和emails.
objRegExp.IgnoreCase = True
' 設置大小寫不敏感..
objRegExp.Global = True
' 全局適用.
Set objMatches = 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 = "a href="""
If UCase(urlType) = "WEB" Then
If LCase(Left(url, 3)) = "www" Then
strBuf = "a href=""URL:" url """超級鏈接:""" _
Target """>" url "/a>"
Else
strBuf = "a href=""" url """超級鏈接:""" _
Target """>" url "/a>"
End If
ElseIf UCase(urlType) = "EMAIL" Then
strBuf = "a href=""電子郵件地址:" url """鏈接目標:""" _
Target """>" url "/a>"
End If
GetHref = strBuf
End Function
[1]
您可能感興趣的文章:- 易語言將指定的主機名與IP地址轉換功能
- PHP實現將優酷土豆騰訊視頻html地址轉換成flash swf地址的方法
- 將IP地址轉換為整型數字的PHP方法、Asp方法和MsSQL方法、MySQL方法
- 兩端口路由器地址轉換的例子
- Cisco 路由器動態和靜態地址轉換
- FormatRemoteUrl函數之asp實現格式化成當前網站完整的URL-將相對地址轉換為絕對地址的代碼
- 使用網絡地址轉換實現多服務器負載均衡
- NAT網絡地址轉換詳情