02-19-2008, 03:11 PM
Hi, i have a list of sites, but need to have a script to cut down each string.
like this for example:
url = "http://www.website.com/35rf/eegweg/index.html"
this needs to become
url = "www.website.com"
so strips out the http:// and anything after the first / leaving just the domain.
02-19-2008, 03:21 PM
Instr for "//" (if found) then use that location plus two as the starting point and Instr for "/". Use Mid$ to get the substring.
02-19-2008, 03:29 PM
hehe... yeah.. thats a good way... now for me to find out how to use it :D
but wouldnt that get everything after the http:// ?. i want whats betweek the http:// and the next /
oh and i guess id need to replace "http://" with "" and then look for first / otherwise it will find the / from http://
02-19-2008, 07:11 PM
Start the Instr() search for the "/" at the position found for the "//" plus 2.
02-20-2008, 01:27 AM
You can also use this class created by Oleg Gdalevich (www.vbip.com)
Because www.vbip.com is no longer there I have attached the source.
You can use the CrackUrl method of the class.
02-20-2008, 06:42 AM
I believe that you could use the Split function with "/" as the delimiter. The piece that you want should end up in the A$(2) cell of the receiving array.
02-20-2008, 04:50 PM
Don't forget that URLs can have a port number in them, a user/pw, etc.
This is why using a generalized parser class somebody else has already debugged can be a big time saver.
What will you do about HTTPS:, FTP:, etc. protocols if you "shave off" and discard them?
02-21-2008, 08:36 AM
I sometimes find it easier to start from the right side of a string and work my way back through it.
(from the right)
Find the first ":"
Find the first "/"
Is ":" position > "\" if so then we have a port #
Then just work backwards through the string to find the "://"
If you are using VB5 (like me then you don't have the Join/Split/ReadUntil/StrReverse/InstrRev/Replace string functions....
MS has a .Bas file up to give us VB5'ers those functions... (I attach it in case it helps someone)