Solved

Parse text and create HTML links where appropriate

Posted on 2004-04-19
8
811 Views
Last Modified: 2009-12-16
I am looking for the following stored procedure:

  CREATE PROCEDURE spActivateLinks

     @text varchar(8000)

  AS
     
       -- all code would go here


  GO



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

I simply want it to activate any potential HTML links that are contained in the text passed to it.
The following text would be parsed and converted to a link:


  * External sites - "http://", "news://", "ftp://" etc etc
  * Local Links - "/news" or "/news/" etc etc

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

Alternatively, this can be achieved in C# but I would prefer it in SQL.
  *
0
Comment
Question by:smacca
[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
8 Comments
 

Author Comment

by:smacca
ID: 10859017
I noticed that Expert Exchange already do exactly what I want to:

  * Notice how the "http://" and "ftp://" have been made into links.

That is EXACTLY what I want to achieve.

Cheers.
0
 
LVL 26

Expert Comment

by:Hilaire
ID: 10859073
Does you text already have some html tags
like
<HTML>
<BODY>
your text here
</BODY>
</HTML>

??

Could you post a sample text for us to work on ?

Hilaire
0
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 200 total points
ID: 10859116
If you are in a.Net environment, I'm sure this could be achieved very easily using regular expressions in your C# app.
Using merely 2-3 lines of code.
Maybe you should give it a try ?

Hilaire
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 3

Expert Comment

by:jayrod
ID: 10859302
I agree with hilaire here. I'm sure it would be possible to do some sort of string replacement. however the problem is that it would be much more effecient and easier to use a language that supports reg expressions
0
 
LVL 34

Expert Comment

by:arbert
ID: 10859334
I agree with the above.  It's not totally clear what you're working with, but usually it's the client application that decides if a link is encoded as an HREF--not the database app....
0
 
LVL 26

Assisted Solution

by:Hilaire
Hilaire earned 200 total points
ID: 10859915
here's a link to single lined function that should do the job

http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=423

I guess you'll manage to update the code so that it handles FTP urls too ...

Hilaire
0
 
LVL 5

Accepted Solution

by:
a1x earned 300 total points
ID: 10860792
You can use SQL server string functions to do what you want.  It is tedious and verbose compared to regular expressions, but it can be done.

Here is a sample that will create a link:

DECLARE @text varchar(4000)

SET @text = 'Turn http://www.yahoo.com into a hyperlink'

DECLARE @StartIndex smallint
DECLARE @EndIndex smallint
DECLARE @URL varchar(4000)

SET @StartIndex = charindex('http:', @text)
SET @EndIndex = charindex(' ', @text, @StartIndex)
SET @URL = substring(@text, @StartIndex, @EndIndex - @StartIndex)

SELECT STUFF(@text, @StartIndex, @EndIndex - @StartIndex, '<a href="' + @URL + '">' + @URL + '</a>')

The sample is very limited.  It only handles one reference in the string.  You would have to add indexes to handle multiple instances of http in the string.  Also, it assumes that the reference ends with space, which may not be the case.  
0
 

Expert Comment

by:Mustangz
ID: 12381131
I was wondering, does anyone know how to do this in ASP?
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

696 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