| View previous topic :: View next topic |
| Author |
Message |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1753 Location: Space and Time
|
Posted: Thu Mar 20, 2003 2:24 pm Post subject: Extract URL/email address from a string |
|
|
I'm having a wee bit of trouble. I want to extract a URL or Email
address from a string no matter what is on front or behind the
address or URL, but, I'm not sure how to go about it. The URL can
start with ither http:// or www. I know to look for the @ in an address
but, I'm having brain trouble. Here is some example strings;
Got to this site! [b]http://www.cgsoft.us[/b]
or
Email me at [i]chris@cgsoft.us please.[/i]
or
Check this out www.cgsoft.us. It's a great site!
Yes the BBC code is to be there.
Thanks for any help, _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Thu Mar 20, 2003 2:35 pm Post subject: |
|
|
If you want the html tags, hyperlinks to another site or page :<a href="http://www.somesite.com">Some Site Name</a>
Hyperlinks to an email address: <a href="mailto://someone@some.com">Contact Me</a> _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1753 Location: Space and Time
|
Posted: Thu Mar 20, 2003 3:00 pm Post subject: |
|
|
I just want to take a normal string without HTML code and extract
and email or URL. The string may or may not have BBCode in it
but it does not have HTML code. Know what I mean?  _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Thu Mar 20, 2003 3:06 pm Post subject: |
|
|
gotcha
| Code: |
%%source = 1234567 zippy do da http://www.some.com some more jibberish
%P = @pos(http://,%%source)
if @greater(%%source,0)
%P = @sum(%P,7)
%%sub = @substr(%%source,%P,@len(%%source))
%%P2 = @pos(@chr(32),%%sub)
if @greater(%%P2,0)
%%url = @substr(%%source,%P,@pred(@sum(%P,@pred(%%P2))))
end
end
|
Is that what ya meant?
EDIT - Extracts text after "http://" up to the next space. No longer pseudo code.  _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it."
Last edited by ShinobiSoft on Thu Mar 20, 2003 3:50 pm; edited 1 time in total |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Mar 20, 2003 3:32 pm Post subject: |
|
|
When using that code I get <http://www.some.com s>. _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Thu Mar 20, 2003 3:41 pm Post subject: |
|
|
The above code is from off the top of my head. That's what "Pseudo Code"
stands for. But how are you getting the "<" and ">" from that string ? _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1753 Location: Space and Time
|
Posted: Thu Mar 20, 2003 3:43 pm Post subject: |
|
|
Kind of...I think I found a work around....Thanks for the help. _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Mar 20, 2003 3:44 pm Post subject: |
|
|
I'm not, perhaps they are confusing. I put them there to show no spaces.  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Thu Mar 20, 2003 3:51 pm Post subject: |
|
|
I've edited my code post to correct the code. It now extracts the text as
specified in the EDIT note.  _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Mar 20, 2003 3:55 pm Post subject: |
|
|
I'm still not advanced at strings, etc. and I thought the following would
work, but why not?
| Code: | %%input = Take a look at http://www.vdsworld.com/ for many extensions and articles.
%%pos1 = @pos(http://,%%input)
%%SubStr = @substr(%%input,%%pos1,@len(%%input))
%%pos2 = @pos(@chr(32),%%SubStr))
%%URL = @substr(%%SubStr,0,%%pos2)
info %%URL |
_________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Thu Mar 20, 2003 4:04 pm Post subject: |
|
|
This line:
| Code: |
%%pos2 = @pos(@chr(32),%%SubStr))
|
It has an extra ")" on the end of it . _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
ShinobiSoft Professional Member


Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Thu Mar 20, 2003 4:06 pm Post subject: |
|
|
Oops.
And this line:
| Code: |
%%URL = @substr(%%SubStr,0,%%pos2)
|
should be:
| Code: |
%%URL = @substr(%%SubStr,1,@pred(%%pos2))
|
strings are counted from 1 in VDS not zero like in C/C++  _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Mar 20, 2003 4:10 pm Post subject: |
|
|
Thanks for your comments. Here's one that works too:
| Code: | %%input = Take a look at http://www.vdsworld.com/ for many extensions and articles.
%%pos1 = @pos(http://,%%input)
%%SubStr = @substr(%%input,%%pos1,@len(%%input))
%%pos2 = @pos(@chr(32),%%SubStr)
%%URL = @substr(%%SubStr,1,%%pos2)
info %%URL |
_________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Thu Mar 20, 2003 4:40 pm Post subject: |
|
|
Hey FF,
Ya might wanna try my code checker when ya have a lot
of "( )" in your code. If there's any mismatched, it tells ya
which line it's on, how many are missing, and whether it's
left or right brackets.
Also checks IF/END, REPEAT/UNTIL, and WHILE/WEND
matches, subprocedure nesting, and finds variables.
http://www.vdsworld.com/forum/viewtopic.php?t=1322
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Thu Mar 20, 2003 5:04 pm Post subject: |
|
|
Thanks, Mac! I think this will help a lot in my future coding!  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
| Back to top |
|
 |
|