Code Title: Auto-linking
Description: How would you like to have every instance of an http:// 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:
-------------------------------------------------------------------------
1
2Function LinkURLs(strInput)
3iCurrentLocation = 1
4Do While InStr(iCurrentLocation, strInput, "http://", 1) <> 0
5iLinkStart = InStr(iCurrentLocation, strInput, "http://", 1)
6iLinkEnd = InStr(iLinkStart, strInput, " ", 1)
7If iLinkEnd = 0 Then iLinkEnd = Len(strInput) + 1
8Select Case Mid(strInput, iLinkEnd - 1, 1)
9Case ".", "!", "?"
10iLinkEnd = iLinkEnd - 1
11End Select
12strOutput = strOutput & Mid(strInput, iCurrentLocation, iLinkStart - iCurrentLocation)
13strLinkText = Mid(strInput, iLinkStart, iLinkEnd - iLinkStart)
14strOutput = strOutput & "
<a "&strlinktext&"""="" href="">"&strLinkText&"</a>
1"
2iCurrentLocation = iLinkEnd
3Loop
4strOutput = strOutput & Mid(strInput, iCurrentLocation)
5LinkURLs = strOutput
6End Function
7strUnlinked = "http://LINE9.com rules!
<br/>
1" & vbCrLf
2strUnlinked = strUnlinked & "http://pdxpc.com sells great computers!
<br/>
1" & vbCrLf
2
3' Here is the before text:
4Response.Write "
<b>Original Text:</b>
<br/>
1" & vbCrLf
2Response.Write strUnlinked
3Response.Write vbCrLf & "
<br/>
1" & vbCrLf & vbCrLf
2
3' Here is the text after it gets automatically hyperlinked to itself:
4Response.Write "
<b>Text After Linking:</b>
<br/>
1" & vbCrLf
2Response.Write LinkURLs(strUnlinked)
-------------------------------------------------------------------------