473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 5145
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sambalaz | last post by:
What is the best way to achieve authentication between two seperate non trusting domains. Scenario: - i have a winform client application that resides on domain A - the application makes calls...
2
by: Jordan | last post by:
Suppose I register a domain name, MyDomain.com, through register.com (or any other of the many domain name registrars). I own the domain name. The domain name goes into the global DNS database. ...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
5
by: Dany C. | last post by:
We have install a valid SSL certificate issued to www.mycompany.com on our web server running IIS 6.0 / win2003 SP1. Then we have created a sub domain pointing to the same server for our web...
3
by: Jason Hawthorne | last post by:
I am trying to get this code to work in a class file that I use in all of my pages. Public Shared Function Check_Site() As String Dim arr() As String Dim coll As NameValueCollection coll...
1
by: dandorey1 | last post by:
I'm currently in the process of writing a realtime telephony application. I've designed it with a fairly simply plugin architecture. When I first started reading about this the general suggestion...
7
by: MarkusJNZ | last post by:
Hi, I have a website called www.websitename.com which is an ASP.NET 2.0 website. I need to create another application (Which I want to be totally seperate from the above website) but for...
6
by: Guy Macon | last post by:
While I agree with the sentiment, the oringinal title on this thread ("OT: Specially for , why you should always use example.com for obfuscating domains") is wrong. There are other reserved domain...
3
by: yaghout | last post by:
Hi, i need to check and retrive the mx records for a domain using asp .net , i am using .net 1.1 and prefer to use this framework version . ok , i found that i should use DNS protocol to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.