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

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="">"&amp;strLinkText&amp;"</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)   

-------------------------------------------------------------------------

Published At
Categories with Web编程
Tagged with
comments powered by Disqus