Solved

Find string and turn into hyperlink

Posted on 2013-02-06
5
305 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
ID: 38862599
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 31

Accepted Solution

by:
Wayne Barron earned 310 total points
ID: 38862689
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
ID: 38862717
Carrzkiss,

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

See the extra "http//"
0
 

Author Comment

by:rrhandle8
ID: 38862738
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 31

Expert Comment

by:Wayne Barron
ID: 38862794
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Executing a script on a timer online 5 32
CREATE DATABASE 3 34
Html value of radio 14 43
IIS 7 and executing pages using localhost 16 24
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

679 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