Solved

Find string and turn into hyperlink

Posted on 2013-02-06
5
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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