Connecting Tech Pros Worldwide Forums | Help | Site Map

Seperate Domain name from url

gsecrets@gmail.com
Guest
 
Posts: n/a
#1: Sep 12 '06
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


PBsoft
Guest
 
Posts: n/a
#2: Sep 12 '06

re: Seperate Domain name from url


URL
Quote:
============
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


gsecrets@gmail.com
Guest
 
Posts: n/a
#3: Sep 12 '06

re: Seperate Domain name from url


Hi Don't think that solves the problem....

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

Jens Schilling
Guest
 
Posts: n/a
#4: Sep 12 '06

re: Seperate Domain name from url


Hi
Quote:
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




PBsoft
Guest
 
Posts: n/a
#5: Sep 12 '06

re: Seperate Domain name from url


Hi Don't think that solves the problem....
Quote:
>
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


gsecrets@gmail.com
Guest
 
Posts: n/a
#6: Sep 13 '06

re: Seperate Domain name from url


Thanks .. that works cool

Ganesh J. Acharya
Jens Schilling wrote:
Quote:
Hi
>
Quote:
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
gsecrets@gmail.com
Guest
 
Posts: n/a
#7: Sep 14 '06

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
>
Quote:
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
Jens Schilling
Guest
 
Posts: n/a
#8: Sep 14 '06

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









gsecrets@gmail.com
Guest
 
Posts: n/a
#9: Sep 15 '06

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

Jens Schilling
Guest
 
Posts: n/a
#10: Sep 15 '06

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


gsecrets@gmail.com
Guest
 
Posts: n/a
#11: Sep 16 '06

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
Jens Schilling
Guest
 
Posts: n/a
#12: Sep 16 '06

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



gsecrets@gmail.com
Guest
 
Posts: n/a
#13: Sep 23 '06

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
Jens Schilling
Guest
 
Posts: n/a
#14: Sep 23 '06

re: Seperate Domain name from url


Hi,
Quote:
you are right Jens Schilling...
;-)
Quote:
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


Closed Thread


Similar Microsoft Access / VBA bytes