469,898 Members | 1,605 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Seperate Domain name from url

Hi friends..

I have a table with the following ..... fields

URL
Domain

The domain name has the following suffix
..edu, .com, .org, .ca.org etc;

the data in the column looks as follows.

URL
============
http://www.test1.com/contact.asp
http://www.test2.edu/ddd.asp
http://www.test3.co.in/ct.php
http://dsih.test4.co.uk/test.html
""
""

How can I extract the only the domain name from the following list? to
give the following output?

Domain
=========
test1.com
test2.edu
test3.co.in
test4.co.uk
""
"'

Regards
Ganesh J. Acharya

Sep 12 '06 #1
13 4846
URL
============
http://www.test1.com/contact.asp
http://www.test2.edu/ddd.asp
http://www.test3.co.in/ct.php
http://dsih.test4.co.uk/test.html

How can I extract the only the domain name from the following list? to
give the following output?

Domain
=========
test1.com
test2.edu
test3.co.in
test4.co.uk
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
Sep 12 '06 #2
Hi Don't think that solves the problem....

what if the string is http://subdomain.test123.com/testpage.html

Sep 12 '06 #3
Hi
Hi Don't think that solves the problem....

what if the string is http://subdomain.test123.com/testpage.html
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


Sep 12 '06 #4
Hi Don't think that solves the problem....
>
what if the string is http://subdomain.test123.com/testpage.html
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
Sep 12 '06 #5
Thanks .. that works cool

Ganesh J. Acharya
Jens Schilling wrote:
Hi
Hi Don't think that solves the problem....

what if the string is http://subdomain.test123.com/testpage.html

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
Sep 13 '06 #6
no buddy it's not working..

if i remove "www" it just does not work

thanks!
ganesh

Jens Schilling wrote:
Hi
Hi Don't think that solves the problem....

what if the string is http://subdomain.test123.com/testpage.html

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
Sep 14 '06 #7
Hi
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



Sep 14 '06 #8
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

Sep 15 '06 #9
Hi,
this one worked for me
Following your first post, it won't......
>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
Sep 15 '06 #10
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:
Hi,
this one worked for me

Following your first post, it won't......
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
Sep 16 '06 #11
Hi,
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
>?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

Sep 16 '06 #12
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

gs******@gmail.com wrote:
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:
Hi,
this one worked for me
Following your first post, it won't......
>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
Sep 23 '06 #13
Hi,
you are right Jens Schilling...
;-)
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
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
Sep 23 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jordan | last post: by
5 posts views Thread by Dany C. | last post: by
3 posts views Thread by Jason Hawthorne | last post: by
3 posts views Thread by yaghout | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.