当前位置: 首页 > 图文教程 > 网络编程 > 编程10000问 > 如何把URL和邮件地址转换为超级链接?

编程10000问
如何用POP3接收电子邮件?
如何用组件实现自动发送电子邮件?
如何编写翻页函数?
如何分页显示数据库查询结果?
如何实现全文检索?
如何用FileSystemObject组件来做一个站内搜索?
如何做一个文本搜索?
如何做一个只搜索本网站的引擎?
如何实现歌曲在线点播?
如何实现网上考试?
网上考试设计思路是怎样的?
可以让程序告诉我详细的页面错误和数据库连接错误吗?
如何把Recordset转换成彩色的XML文件
如何把URL和邮件地址转换为超级链接?
如何把一个Excel文件放到ASP页面中去?
如何把中文转换为UNICODE?
如何编写TOP 10之类的排行榜?
如何动态添加Form项?
如何读取一个.ini文件?
如何计算ASP页面的载入时间?

编程10000问 中的 如何把URL和邮件地址转换为超级链接?


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 101 ::
收藏到网摘: n/a

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"

' 判断URLsemails.
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]