当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP为字符串中的网址自动加上链接

ASP
在ASP文件中调用DLL
ASP服务器组件的编程
在ASP.NET访问Excel文件
ADO.NET:通向未来之桥
ASP.Net的几大热点问题
DataList控件也玩分页
ASP.NET高级应用(1)
ASP.NET高级应用(2)
ASP.NET高级应用(3)
关于ASP.Net中的时间处理
ASP编写完整的一个IP所在地搜索类
ASP发送E-MAIL
建立MSXML 测试环境
怎样创建.NET Web Service
怎样创建.NET Web Service(2)
怎样创建.NET Web Service(3)
怎样创建.NET Web Service(4)
ASP.NET中的HTMLControl和WebControl
比尔·盖茨在微软开发者成功之路大会上的主题演讲
运用.NET读写Windows注册编辑表

ASP为字符串中的网址自动加上链接


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 268 ::
收藏到网摘: n/a

asp下用正则实现字符串中的网址加链接的代码 <%
'字段内网址加上联接。
Function ToLink(Str)
Dim RE '正则表达式对象 Dim strContent
If IsNull(Str) Then Str = ""
Set RE = New RegExp '创建正 则表达式对象
With RE
.Global = True '搜索应用于整个字符串
.IgnoreCase = True '搜索不区分大小写的
strContent = Str
'***************************************************************
'邮件地址链接自动设置
'***************************************************************
.Pattern = "([\w]*)@([\w\.]*)"
strContent = .Replace(strContent, "<A Href='mailto:$1@$2'>$1@$2</A> ")
'***************************************************************
'链接自动设置
'***************************************************************
'======根据要求再添加协议名称=======
Dim D(3), I
D(0) = "http"
D(1) = "ftp"
D(2) = "news"
D(3) = "mms"
'===================================
For I = 0 To UBound(D)
.Pattern = D(I) + ":\/\/([\w\.]*)"
strContent = .Replace(strContent, "<A Href='" + D(I) + "://$1' target=_blank>" + D(I) + "://$1</A> ")
Next
'***************************************************************
End With
Set RE = Nothing
ToLink = strContent
End Function
%>