当前位置: 代码网 > it编程>编程语言>其他编程 > 如何把URL和邮件地址转换为超级链接?

如何把URL和邮件地址转换为超级链接?

2024年05月15日 其他编程 我要评论
function inserthyperlinks(intext)dim objregexp, strbufdim objmatches, objmatchdim value, replacevalu

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]

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com