| Author |
Topic Search Topic Options
|
C.P.A.
Newbie
Joined: 26 April 2005
Location: Netherlands
Status: Offline
Points: 26
|
Post Options
Thanks(0)
Quote Reply
Topic: address convertion to link 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.
Edited by C.P.A. - 26 April 2005 at 10:12am
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
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
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.
Edited by dpyers - 26 April 2005 at 1:48pm
|
Lead me not into temptation... I know the short cut, follow me.
|
 |
C.P.A.
Newbie
Joined: 26 April 2005
Location: Netherlands
Status: Offline
Points: 26
|
Post Options
Thanks(0)
Quote Reply
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;
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:
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.
Edited by C.P.A. - 26 April 2005 at 6:40pm
|
 |
Gullanian
Senior Member
Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
|
Post Options
Thanks(0)
Quote Reply
Posted: 26 April 2005 at 7:06pm |
|
Are regular experessions good for this job? I don't really know much about them.
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |
C.P.A.
Newbie
Joined: 26 April 2005
Location: Netherlands
Status: Offline
Points: 26
|
Post Options
Thanks(0)
Quote Reply
Posted: 26 April 2005 at 7:23pm |
|
Gonna try it :)
I'll keep ye posted
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
Posted: 26 April 2005 at 7:28pm |
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.
Edited by dpyers - 26 April 2005 at 7:31pm
|
Lead me not into temptation... I know the short cut, follow me.
|
 |
C.P.A.
Newbie
Joined: 26 April 2005
Location: Netherlands
Status: Offline
Points: 26
|
Post Options
Thanks(0)
Quote Reply
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!
Edited by C.P.A. - 26 April 2005 at 7:44pm
|
 |