Solved

Find string and turn into hyperlink

Posted on 2013-02-06
5
291 Views
Last Modified: 2013-02-06
I need to find URLs in some text, and then create hyperlinks.

Example Input:
You can find the answer at http://www.ask.com or you can try http://www.answers.com.

Example Output
You can find the answer at <a href='http://www.ask.com'>http://www.ask.com</a> or you can try <a href='http://www.ask.com'>http://www.answers.com</a>.
0
Comment
Question by:rrhandle8
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Kent Dyer
Comment Utility
Something like..  You will need to do some changing..

If instr(fieldname, "http://") Then
Replace (fieldname,"<a href='")
Else If instr(fieldname, ".com")
Replace (fieldname,".com</a>")
End If

Open in new window


here is a more complete example..
http://www.motobit.com/tips/detpg_replace-relative-links/

HTH,

Kent
0
 
LVL 30

Accepted Solution

by:
Wayne Barron earned 310 total points
Comment Utility
Here you go
http://ee.cffcs.com/Q_28023092/Q_28023092.asp
code
http://ee.cffcs.com/Q_28023092/Q_28023092.zip

The only thing is, that you have to have the
http://
at the beginning, in order for it to process it as a link.

Hope this helps.
Carrzkiss
0
 

Author Comment

by:rrhandle8
Comment Utility
Carrzkiss,

Perfect, but a small flaw.  http://http//www.ask.com.

See the extra "http//"
0
 

Author Comment

by:rrhandle8
Comment Utility
Here is how I fixed it.
' create anchors from URLs
' Updated by Wayne Barron on 2/07/2013
' This first one, will allow you to only write the url, without the http://

Commented out this line
' Text = regEx.Replace(Text, "<a href=""http://$1"">$1</a>")

' This one, you have to provide the http:// in order to process it as a URL
Text = regEx.Replace(Text, "<a href=""$1"">$1</a>")
0
 
LVL 30

Expert Comment

by:Wayne Barron
Comment Utility
Yea, I was trying something and THOUGHT that I had it working, and jumped the gun and uploaded the newer copy.
However, if you download it now, it is the original code, as I could not get the other one working.
Which was, to make it so you did not have to type in the http://
However, I thought it worked, but it did not.
So, that was the reason for the http:// being embedded in the code like it was.

Have a good one.
Carrzkiss
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now