Print Page | Close Window

address convertion to link

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=14841
Printed Date: 30 March 2026 at 6:37am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: address convertion to link
Posted By: C.P.A.
Subject: address convertion to link
Date Posted: 26 April 2005 at 10:11am
Dear people,

Does anyone know how I can convert a address such as: http://www.somesite.com into a working hyperlink when these addresses are gotten from a string with other text inside of them?

a for instance string contains: blabla bla bla http://www.bla.com blabla bla bla bla...

should become: blabla bla bla <a href=""http://www.bla.com"" title=""open page"">open page</a> blabla bla bla bla...

Many thanks in advance,

Yours sincerely,

C.P.A.


-------------
C.P.A. » The more you find out about the world, the more opportunities warmly welcome you.



Replies:
Posted By: dpyers
Date Posted: 26 April 2005 at 1:45pm
This routine will search strText for the start and end characters passed to PullStrings - e.g. http and the first space following it.
It returns everything between those characters in strReturned
 
Quote
Dim strText   'A string containing the text we want searched
Dim strReturned   'A string containing the search results
Dim strSearchString  'The characters found at the beginning of the string we want
Dim strEndStringChars 'The characters found at the end of the string we want
Dim strStartPos   'The position in strText that we start searching from
Dim strEndPos   'The position in strText that we end searching
Dim strLength   'The length of data between the start and end search strings
 
Sub subPullStrings(strSearchString, strEndStringChars)

    strLength = 0
    strStartPos = instr(strStartPos, strText, strSearchString)
   
    strEndPos = instr(strStartPos + 1, strText, strEndStringChars)
   
    strLength = strEndPos - strStartPos
   
   'Pluck the string out of the page text
   'Since strStartPos is the start of the strSearchString, not the end of it,
   'and we only want the data between strSearchString and strEndStringChars,
   'we add the length of the strSearchString to strStartPos and subtract it from the length
   'of the found string to get the actual start position and length of the data between the two.
   strReturned = mid(strText,strStartPos + len(strSearchString),strLength - len(strSearchString) ) 
    
   'bump up the start position for when we look for the next occurrence of the string so
   'we don't start looking from the beginning again.
    strStartPos = strEndPos + 1

End Sub
 
strText = TheTextContainingTheURL
subPullStrings "http:">", " "
Response.Write "<br/>The Returned Text = " & strReturned & <br/>
 
EDIT: It'll toss an error if either the start or the ending string isn't in the text being searched.


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

Lead me not into temptation... I know the short cut, follow me.


Posted By: C.P.A.
Date Posted: 26 April 2005 at 6:02pm
I'm sorry but I do not seem to get it working it complains about an inStr error in line 21 which is the first method using the inStr.

Also I am a bit confused about the lower part;

Quote subPullStrings "http:">", " "
Response.Write "<br/>The Returned Text = " & strReturned & <br/>


This never will work, however I am not sure if it is supposed to be:

Quote subPullStrings "http:",">", " "
Response.Write "<br/>The Returned Text = " & strReturned & "<br/>"


or ...

Because it is supposed to be like:
<a href="http://www.link.com">open link</a>


I really would love if ye could help me a bit more.

Many thanks, I really appreciate it.

-------------
C.P.A. » The more you find out about the world, the more opportunities warmly welcome you.


Posted By: Gullanian
Date Posted: 26 April 2005 at 7:06pm
Are regular experessions good for this job?  I don't really know much about them.


Posted By: dpyers
Date Posted: 26 April 2005 at 7:19pm
Try changing that line to
strStartPos = instr(1, strText, strSearchString)
I usually manage the start position initialization elsewhere as I use this routine to walk through a string several times looking for various pieces of text in sequence. The changed line will always start from position 1 in the string to be searched.
 
Make sure that  TheTextContainingTheURL is replaced by the name of the string containing your data. Also make sure that the test string contains a url followed by a space.
 
The response write was just an example because I didn't feel like working out the number of quotes. For your example, you'd replace it with something like
Response.write "<a href=""" & strReturned & """>open link</a>"
 
 
 
 


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

Lead me not into temptation... I know the short cut, follow me.


Posted By: C.P.A.
Date Posted: 26 April 2005 at 7:23pm
Gonna try it :)

I'll keep ye posted

-------------
C.P.A. » The more you find out about the world, the more opportunities warmly welcome you.


Posted By: dpyers
Date Posted: 26 April 2005 at 7:28pm
Originally posted by Gullanian Gullanian wrote:

Are regular experessions good for this job?  I don't really know much about them.
 
You could do it with an RE but it's harder to explain and trouble shoot - for me anyway - lol. Also, I tend to think of RE's as editing/formatting for smaller strings. I think (but don't know) that Instr, Mid, Left, Right, etc. are more useful for large strings than RE's are.
 
I use stuff like PullStrings (often as a function instead of a sub) to pull data from web pages. It's easier to update than an RE for me when someone changes the third <div class="x"> on a page to the fourth div. I can also response write the input and various strings/intergers within the routines to trouble shoot.


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

Lead me not into temptation... I know the short cut, follow me.


Posted By: C.P.A.
Date Posted: 26 April 2005 at 7:43pm
To make sure other people can use it as well for their purposes:

And a great many thanks to dpyers


<%
Dim strText   'A string containing the text we want searched
Dim strReturned   'A string containing the search results
Dim strSearchString 'The characters found at the beginning of the string we want
Dim strEndStringChars 'The characters found at the end of the string we want
Dim strStartPos   'The position in strText that we start searching from
Dim strEndPos   'The position in strText that we end searching
Dim strLength   'The length of data between the start and end search strings

Sub subPullStrings(strSearchString, strEndStringChars)

    strLength = 0
     strStartPos = instr(1, strText, strSearchString)
    strEndPos = instr(strStartPos + 1, strText, strEndStringChars)
   
    strLength = strEndPos - strStartPos
   
   'Pluck the string out of the page text
   'Since strStartPos is the start of the strSearchString, not the end of it,
   'and we only want the data between strSearchString and strEndStringChars,
   'we add the length of the strSearchString to strStartPos and subtract it from the length
   'of the found string to get the actual start position and length of the data between the two.
   strReturned = mid(strText,strStartPos + len(strSearchString),strLength - len(strSearchString) )
    
   'bump up the start position for when we look for the next occurrence of the string so
   'we don't start looking from the beginning again.
    strStartPos = strEndPos + 1

End Sub
TheTextContainingTheURL = "a couple of very fine people are always willing to help ye out of problems, they can be http://forums.webwiz.net/forum_posts.asp?TID=14841&PN=1&TPN=1 and really I appreciate their help."
strText = TheTextContainingTheURL
subPullStrings "http:", " "
strFinal = "<a href=""" + strReturned + """>found here</a>"

strText = Replace(strText,strReturned,strFinal)
strText = Replace(strText,"http:"," ")
Response.Write(strText)
%>



To please ye!


-------------
C.P.A. » The more you find out about the world, the more opportunities warmly welcome you.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net