Solved

Find string and turn into hyperlink

Posted on 2013-02-06
5
307 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

Suggested Solutions

Title # Comments Views Activity
html Uncheck Checkbox 2 35
VBScript on Html 15 64
PHP encrypted string and passing to a ASP Page 12 81
2012 SQL to JSON Select 5 42
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 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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

736 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