如何把URL和邮件地址自动转换为超级链接?
来源:asp之家 发布时间:2009-11-02 20:22:00
我们可用正规表达式来寻找并替换URL和邮件地址为活动的超级链接。
用到的主要函数就是InsertHyperlinks(inText),语法为:
InsertHyperlinks(inText)
返回值: inText = "<a href="URL" target="_BLANK">URL</a>"
插入(存储)找到的URL和邮件地址。它对URL的判断是以www或http标志开头,对邮件地址的判断是含有@符,够酷吧?
好了,看看这个函数的用法:
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
猜你喜欢
- Series对象和DataFrame的列数据提供了cat、dt、str三种属性接口(accessors),分别对应分类数据、日期时间数据和字
- torch.nn.Modules 相当于是对网络某种层的封装,包括网络结构以及网络参数和一些操作torch.nn.Module 是所有神经网
- 01前言数据是数据科学中任何分析的关键,大多数分析中最常用的数据集类型是存储在逗号分隔值(csv)表中的干净数据。然而,由于可移植文档格式(
- 在使用echarts的自定义饼图Customized Pie时,定义的动态数据会发生颜色无法渲染的问题,如下图所示:该图表的颜色是根据ite
- 导入注意点:使用phpmyadmin或navicat之类的工具的导入功能还是会相当慢,可以直接使用mysql进行导入导入命令如下:mysql
- 支持聚合函数的方法:提到聚合函数,首先我们要知道的就是这些聚合函数是不能在django中单独使用的,要想在django中使用这些聚合函数,就
- 小编想把用python将列表[1,1,1,1,1,1,1,1,1,1] 和 列表 [2,2,2,2,2,2,2,2,2,2]对应相加成[3,
- 在我们使用log模块输出日志时,经常会遇到log输出重复的问题,如下:先来看这个文件log.py的代码:代码示例:''
- 以下内容在python中完全可以接受:1、将整数的字符串表示形式传递给 int2、将float的字符串表示形式传递给 float但是,如果你
- 概要贝叶斯网络是一种基于概率的图模型,可用于建立变量之间的条件概率关系。在拼写检查器中,贝叶斯网络可以通过建立一个隐含状态、错误观察值和正确
- 目录一、jieba库概述二、jieba库安装三、jieba分词的原理四、jieba分词的3种模式五、jieba库常用函数六、文本词频示例七、
- Linux+apache+mysql+python+mod_python+Django说明:系统rhel 5.3,默认安装httpd、mys
- 上传组件封装需求分析在基于elementUI库做的商城后台管理中,需求最大的是商品管理表单这块,因为需要录入各种各样的商品图片信息。加上后台
- 目录小而美简单至上避免空值选择数据类型的步骤数据类型介绍一、串数据类型二、数值数据类型三、日期和时间数据类型四、二进制数据类型结语:小而美通
- 前言在前几年,如果你和嵌入式开发人员推荐Python,大概会是这样一种场景:A:”诶,老王,你看Python开发这么方便
- 1、代码如下:import numpy as npfrom keras.models import Sequentialfrom keras
- 本文实例总结了python调用函数、类和文件操作。分享给大家供大家参考,具体如下:调用函数有三种方式一,导入整个模块(所有函数)导入 imp
- Python 截取字符串使用 变量[头下标:尾下标],就可以截取相应的字符串,其中下标是从0开始算起,可以是正数或负数,下标可以为空表示取到
- 之前捣鼓树莓派时,要求做一个番茄钟,但最后就只是搞成一个与树莓派没啥关系的py程序,虽然简陋,但就此记录一下自学的成果。程序实现番茄工作法:
- 很类似java的properties文件xml文件db_config.ini[baseconf]host=127.0.0.1port=330