欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

转换字符串带有http://的超级链接字符串为真正的超级链接(源码)

程序员文章站 2022-03-09 21:34:33
code title: auto-linkingdescription: how would you like to have every instance of an https:// auto-...
code title: auto-linking
description: how would you like to have every instance of an https:// auto-hyperlink itself to the url
address that follows it? well, here is a killer little function that will take every one of those that it
finds in a string and sets up the hyperlink for you! cool, eh?
copy and paste this snippet as-is into your editor:

-------------------------------------------------------------------------
<%
function linkurls(strinput)
icurrentlocation = 1
do while instr(icurrentlocation, strinput, "https://", 1) <> 0
ilinkstart = instr(icurrentlocation, strinput, "https://", 1)
ilinkend = instr(ilinkstart, strinput, " ", 1)
if ilinkend = 0 then ilinkend = len(strinput) + 1
select case mid(strinput, ilinkend - 1, 1)
case ".", "!", "?"
ilinkend = ilinkend - 1
end select
stroutput = stroutput & mid(strinput, icurrentlocation, ilinkstart - icurrentlocation)
strlinktext = mid(strinput, ilinkstart, ilinkend - ilinkstart)
stroutput = stroutput & "<a href="""&strlinktext&""">"&strlinktext&"</a>"
icurrentlocation = ilinkend
loop
stroutput = stroutput & mid(strinput, icurrentlocation)
linkurls = stroutput
end function
strunlinked = "https://line9.com rules! <br>" & vbcrlf
strunlinked = strunlinked & "https://pdxpc.com sells great computers!<br>" & vbcrlf

here is the before text:
response.write "<b>original text:</b><br>" & vbcrlf
response.write strunlinked
response.write vbcrlf & "<br>" & vbcrlf & vbcrlf

here is the text after it gets automatically hyperlinked to itself:
response.write "<b>text after linking:</b><br>" & vbcrlf
response.write linkurls(strunlinked)
%>
-------------------------------------------------------------------------