Seperate Domain name from url | | | re: Seperate Domain name from url
URL Use the following code as an example:
Dim strURL As String
Dim strDomain As String
Dim intPos As Integer
strURL = http://www.test2.edu/ddd.asp
intPos = InStr(8, strURL, "/", vbTextCompare)
strDomain = Mid(strURL, 8, intPos - 7)
--
PBsoft di Gabriele Bertolucci www.pbsoft.it
skype: pbsoftsolution | | | | re: Seperate Domain name from url
Hi Try this :
Function SeparateDomain(strDomain As String) As String
Dim i As Long, j As Long, k As Long
k = InStr(1, strDomain, "//") + 2
i = InStr(1, strDomain, ".")
j = InStr(k, strDomain, "/")
SeparateDomain = Mid(strDomain, i + 1, (j - i) - 1)
End Function
Regards
Jens | | | | re: Seperate Domain name from url
Hi Don't think that solves the problem.... Sorry, you are right.
My code extracts only first level domain.
The solution proposed by Jens Schilling seems ok.
--
PBsoft di Gabriele Bertolucci www.pbsoft.it
skype: pbsoftsolution | | | | re: Seperate Domain name from url
Thanks .. that works cool
Ganesh J. Acharya
Jens Schilling wrote: Quote:
Hi
> >
Try this :
>
Function SeparateDomain(strDomain As String) As String
>
Dim i As Long, j As Long, k As Long
>
k = InStr(1, strDomain, "//") + 2
i = InStr(1, strDomain, ".")
j = InStr(k, strDomain, "/")
>
SeparateDomain = Mid(strDomain, i + 1, (j - i) - 1)
>
End Function
>
Regards
Jens
| | | | re: Seperate Domain name from url
no buddy it's not working..
if i remove "www" it just does not work
thanks!
ganesh
Jens Schilling wrote: Quote:
Hi
> >
Try this :
>
Function SeparateDomain(strDomain As String) As String
>
Dim i As Long, j As Long, k As Long
>
k = InStr(1, strDomain, "//") + 2
i = InStr(1, strDomain, ".")
j = InStr(k, strDomain, "/")
>
SeparateDomain = Mid(strDomain, i + 1, (j - i) - 1)
>
End Function
>
Regards
Jens
| | | | re: Seperate Domain name from url
Hi Quote:
no buddy it's not working..
>
if i remove "www" it just does not work
I think it works with all your samples - but changing the rules changes the
results ;-)
All your samples either show a leading "www" or a leading subdomain, so that
it's easy to locate the first dot in the string and cut it respectively.
But if you will let me know how to recognize that a URL like
"http://dsih.test4.co.uk/test.html" contains a subdomain and not only misses
the leading "www" I will try it again.
Regards
Jens | | | | re: Seperate Domain name from url
OK.........
this one worked for me
Dim StrDomain
Dim i As Long, j As Long, k As Long
Dim s() As String
StrDomain = rCell
k = InStr(1, StrDomain, "//") + 2
If InStr(1, StrDomain, "www") 0 Then
i = InStr(1, StrDomain, ".")
Else
i = InStr(1, StrDomain, "//") + 1
End If
j = InStr(k, StrDomain, "/")
StrDomain = Mid(StrDomain, i + 1, (j - i) - 1)
ExtractDomain = StrDomain | | | | re: Seperate Domain name from url
Hi, Quote:
this one worked for me
Following your first post, it won't...... Quote:
>How can I extract the only the domain name from the following list? to
>give the following output?
URL
=========
....... http://dsih.test4.co.uk/test.html
Domain
=========
......
test4.co.uk
Your code in direct window :
?ExtractDomain("http://dsih.test4.co.uk/test.html")
dsih.test4.co.uk
And what about the sample in your second post ?
<http://subdomain.test123.com/testpage.html>
?ExtractDomain("http://subdomain.test123.com/testpage.html")
subdomain.test123.com
Thought you want to cut the subdomain - but when it works for you .....
Regards
Jens | | | | re: Seperate Domain name from url
Yes it is surely cutting the subdomain too....
I've tested that with 300 URL's in my list... it does not make a single
mistake
Jens Schilling wrote: Quote:
Hi,
> Quote:
this one worked for me
>
Following your first post, it won't......
> Quote:
How can I extract the only the domain name from the following list? to
give the following output?
>
URL
=========
...... http://dsih.test4.co.uk/test.html
>
>
Domain
=========
.....
test4.co.uk
>
Your code in direct window :
>
?ExtractDomain("http://dsih.test4.co.uk/test.html")
dsih.test4.co.uk
>
And what about the sample in your second post ?
<http://subdomain.test123.com/testpage.html>
>
?ExtractDomain("http://subdomain.test123.com/testpage.html")
subdomain.test123.com
>
Thought you want to cut the subdomain - but when it works for you .....
>
Regards
Jens
| | | | re: Seperate Domain name from url
Hi, Quote:
Yes it is surely cutting the subdomain too....
I've tested that with 300 URL's in my list... it does not make a
single mistake
Quote: Quote:
>?ExtractDomain("http://subdomain.test123.com/testpage.html")
>subdomain.test123.com
My test with your code results as aforesaid....
Never mind ! It works for you, and that's OK !
Regards
Jens | | | | re: Seperate Domain name from url
Ya this code i paste gives me a sub domain only..
you are right Jens Schilling...
but somehow for the problem i was facing ... i actually need the
subdomain...
good i got that.. but there's another problem in that code...
for http://google.com/ i get google.com
but for http://google.com i don't get anything
ganesh gsecrets@gmail.com wrote: Quote:
Yes it is surely cutting the subdomain too....
>
I've tested that with 300 URL's in my list... it does not make a single
mistake
>
>
Jens Schilling wrote: Quote:
Hi, Quote:
this one worked for me
Following your first post, it won't...... Quote:
>How can I extract the only the domain name from the following list? to
>give the following output?
URL
=========
...... http://dsih.test4.co.uk/test.html
Domain
=========
.....
test4.co.uk
Your code in direct window :
?ExtractDomain("http://dsih.test4.co.uk/test.html")
dsih.test4.co.uk
And what about the sample in your second post ?
<http://subdomain.test123.com/testpage.html>
?ExtractDomain("http://subdomain.test123.com/testpage.html")
subdomain.test123.com
Thought you want to cut the subdomain - but when it works for you .....
Regards
Jens
| | | | re: Seperate Domain name from url
Hi, Quote:
you are right Jens Schilling...
;-) Would expect that you should get at least an error message (error 5 --j =
0) ;-)
So, quick and (very) dirty try :
........
j = InStr(k, strDomain, "/")
If Not j 0 Then
j = InStr(k, strDomain & "/", "/")
End If
Regards
Jens |  | Similar Microsoft Access / VBA bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,419 network members.
|