Hello,
I want to get the right most name of the a domain name, for example:
if the domain is www.myweb.com , I want to get myweb.com
something.myweb .com --> myweb.com www.myweb.com.au --> myweb.com.au
something.myweb .com.au --> myweb.com.au www.myweb.tv --> myweb.tv www.something.myweb.net --> myweb.net
my.test.myweb.c a --> myweb.ca
I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(s tring serverName ) {
if(!serverName. Contains(".")) {
return serverName.ToLo wer();
}
if(serverName.E ndsWith(".co.uk ")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th -
".co.uk".Le ngth - 1) + 1).ToLower();
}
if(serverName.E ndsWith(".com") || serverName.Ends With(".net") ||
serverName.Ends With(".org")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th -
5) + 1).ToLower();
}
return null;
}
Does any one have a better solution?
Adam Tibi 6 2123
Adam,
I'd take a look at the System.Uri class, which has some built-in properties
that simplify segmenting out the portions of a Uri. There may be additional
ways to do it that I'm not aware of.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"Adam Tibi" wrote: Hello,
I want to get the right most name of the a domain name, for example:
if the domain is www.myweb.com , I want to get myweb.com something.myweb .com --> myweb.com www.myweb.com.au --> myweb.com.au something.myweb .com.au --> myweb.com.au www.myweb.tv --> myweb.tv www.something.myweb.net --> myweb.net my.test.myweb.c a --> myweb.ca
I want to know if there is a general rule, code or article regarding this issue. I tried the following code, but I am not convinced, because it is not generic public static string GetDomainName(s tring serverName ) {
if(!serverName. Contains(".")) {
return serverName.ToLo wer();
}
if(serverName.E ndsWith(".co.uk ")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - ".co.uk".Le ngth - 1) + 1).ToLower();
}
if(serverName.E ndsWith(".com") || serverName.Ends With(".net") || serverName.Ends With(".org")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - 5) + 1).ToLower();
}
return null;
}
Does any one have a better solution? Adam Tibi
Thank you for the reply Peter, however, I did check it but I couldn't find
this specific requirment
Regards
"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:C6******** *************** ***********@mic rosoft.com... Adam, I'd take a look at the System.Uri class, which has some built-in properties that simplify segmenting out the portions of a Uri. There may be additional ways to do it that I'm not aware of. Peter
-- Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com
"Adam Tibi" wrote:
Hello,
I want to get the right most name of the a domain name, for example:
if the domain is www.myweb.com , I want to get myweb.com something.myweb .com --> myweb.com www.myweb.com.au --> myweb.com.au something.myweb .com.au --> myweb.com.au www.myweb.tv --> myweb.tv www.something.myweb.net --> myweb.net my.test.myweb.c a --> myweb.ca
I want to know if there is a general rule, code or article regarding this issue. I tried the following code, but I am not convinced, because it is not generic public static string GetDomainName(s tring serverName ) {
if(!serverName. Contains(".")) {
return serverName.ToLo wer();
}
if(serverName.E ndsWith(".co.uk ")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - ".co.uk".Le ngth - 1) + 1).ToLower();
}
if(serverName.E ndsWith(".com") || serverName.Ends With(".net") || serverName.Ends With(".org")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - 5) + 1).ToLower();
}
return null;
}
Does any one have a better solution? Adam Tibi
Hi,
Save your primary domain name (myweb) globally. Get the host name with HTTP_HOST server variable and use substring function
e.g.
string tct = @"www.something .myweb.net.au";
MessageBox.Show (tct.Substring( tct.IndexOf("my web")));
Will display out as myweb.net.au
Hope this might help you...
Vinu
"Adam Tibi" <ad*******@nosp am.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Hello, I want to get the right most name of the a domain name, for example: if the domain is www.myweb.com , I want to get myweb.com something.myweb .com --> myweb.com www.myweb.com.au --> myweb.com.au something.myweb .com.au --> myweb.com.au www.myweb.tv --> myweb.tv www.something.myweb.net --> myweb.net my.test.myweb.c a --> myweb.ca I want to know if there is a general rule, code or article regarding this issue. I tried the following code, but I am not convinced, because it is not generic public static string GetDomainName(s tring serverName ) { if(!serverName. Contains(".")) { return serverName.ToLo wer(); } if(serverName.E ndsWith(".co.uk ")) { return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - ".co.uk".Le ngth - 1) + 1).ToLower(); } if(serverName.E ndsWith(".com") || serverName.Ends With(".net") || serverName.Ends With(".org")) { return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - 5) + 1).ToLower(); } return null; } Does any one have a better solution? Adam Tibi
Thank you Vinu,
The problem here is that I don't know the domain name in advance, I am going to get different domain names and I need to parse them, so this solution doesn't work because it assumes that I know the domain name in advance. I want a global solution that will get the last portion of any domain name.
ideas any one?
Regards
Adam Tibi
"vinu" <vi*********@go oglemail.com> wrote in message news:e$******** *****@TK2MSFTNG P09.phx.gbl...
Hi,
Save your primary domain name (myweb) globally. Get the host name with HTTP_HOST server variable and use substring function
e.g.
string tct = @"www.something .myweb.net.au";
MessageBox.Show (tct.Substring( tct.IndexOf("my web")));
Will display out as myweb.net.au
Hope this might help you...
Vinu
"Adam Tibi" <ad*******@nosp am.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Hello, I want to get the right most name of the a domain name, for example: if the domain is www.myweb.com , I want to get myweb.com something.myweb .com --> myweb.com www.myweb.com.au --> myweb.com.au something.myweb .com.au --> myweb.com.au www.myweb.tv --> myweb.tv www.something.myweb.net --> myweb.net my.test.myweb.c a --> myweb.ca I want to know if there is a general rule, code or article regarding this issue. I tried the following code, but I am not convinced, because it is not generic public static string GetDomainName(s tring serverName ) { if(!serverName. Contains(".")) { return serverName.ToLo wer(); } if(serverName.E ndsWith(".co.uk ")) { return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - ".co.uk".Le ngth - 1) + 1).ToLower(); } if(serverName.E ndsWith(".com") || serverName.Ends With(".net") || serverName.Ends With(".org")) { return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - 5) + 1).ToLower(); } return null; } Does any one have a better solution? Adam Tibi
As Peter tried to convey, there's probably a method in a class the framework
provides. The "long hand" way I did this in ASP can still be done using
ASP.NET...
* Get the URL as a string and trim white space from front and back
* Pass the trimmed string to a string reverse method
* Split the reversed string on the . character
* Get the value from the [0]th array indice
* Reverse that value and you get "com", "org", "aero", "name" or whatever
Note when we split a string an array is created. Simply get the value from
the [0]th indice as I indicate and reverse the value and you get what you
want.
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee. com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"Adam Tibi" <ad*******@nosp am.com> wrote in message
news:Ov******** ******@TK2MSFTN GP15.phx.gbl...
Thank you Vinu,
The problem here is that I don't know the domain name in advance, I am going
to get different domain names and I need to parse them, so this solution
doesn't work because it assumes that I know the domain name in advance. I
want a global solution that will get the last portion of any domain name.
ideas any one?
Regards
Adam Tibi
"vinu" <vi*********@go oglemail.com> wrote in message
news:e$******** *****@TK2MSFTNG P09.phx.gbl...
Hi,
Save your primary domain name (myweb) globally. Get the host name with
HTTP_HOST server variable and use substring function
e.g.
string tct = @"www.something .myweb.net.au";
MessageBox.Show (tct.Substring( tct.IndexOf("my web")));
Will display out as myweb.net.au
Hope this might help you...
Vinu
"Adam Tibi" <ad*******@nosp am.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Hello,
I want to get the right most name of the a domain name, for example:
if the domain is www.myweb.com , I want to get myweb.com something.myweb .com --> myweb.com www.myweb.com.au --> myweb.com.au something.myweb .com.au --> myweb.com.au www.myweb.tv --> myweb.tv www.something.myweb.net --> myweb.net my.test.myweb.c a --> myweb.ca
I want to know if there is a general rule, code or article regarding this issue. I tried the following code, but I am not convinced, because it is not generic public static string GetDomainName(s tring serverName ) {
if(!serverName. Contains(".")) {
return serverName.ToLo wer();
}
if(serverName.E ndsWith(".co.uk ")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - ".co.uk".Le ngth - 1) + 1).ToLower();
}
if(serverName.E ndsWith(".com") || serverName.Ends With(".net") || serverName.Ends With(".org")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - 5) + 1).ToLower();
}
return null;
}
Does any one have a better solution? Adam Tibi
Thank you Clinton,
You are assuming that the extention is just one part like "org" or "net" but
it might be "com.au" or "co.uk" and I currently made a solution for the
extentions that I know but I wanted a generic solution that doesn't require
me to check .com.au, .com.lb, .co.uk, ca, net, org, us, info, etc...
I just wanted a general rule for this.
Regards,
Adam Tibi
"clintonG" <cs*********@RE MOVETHISTEXTmet romilwaukee.com > wrote in message
news:eX******** ******@TK2MSFTN GP15.phx.gbl... As Peter tried to convey, there's probably a method in a class the framework provides. The "long hand" way I did this in ASP can still be done using ASP.NET...
* Get the URL as a string and trim white space from front and back * Pass the trimmed string to a string reverse method * Split the reversed string on the . character * Get the value from the [0]th array indice * Reverse that value and you get "com", "org", "aero", "name" or whatever
Note when we split a string an array is created. Simply get the value from the [0]th indice as I indicate and reverse the value and you get what you want.
<%= Clinton Gallagher METROmilwaukee (sm) "A Regional Information Service" NET csgallagher AT metromilwaukee. com URL http://metromilwaukee.com/ URL http://clintongallagher.metromilwaukee.com/
"Adam Tibi" <ad*******@nosp am.com> wrote in message news:Ov******** ******@TK2MSFTN GP15.phx.gbl... Thank you Vinu,
The problem here is that I don't know the domain name in advance, I am going to get different domain names and I need to parse them, so this solution doesn't work because it assumes that I know the domain name in advance. I want a global solution that will get the last portion of any domain name.
ideas any one? Regards Adam Tibi "vinu" <vi*********@go oglemail.com> wrote in message news:e$******** *****@TK2MSFTNG P09.phx.gbl... Hi,
Save your primary domain name (myweb) globally. Get the host name with HTTP_HOST server variable and use substring function
e.g.
string tct = @"www.something .myweb.net.au"; MessageBox.Show (tct.Substring( tct.IndexOf("my web"))); Will display out as myweb.net.au Hope this might help you...
Vinu "Adam Tibi" <ad*******@nosp am.com> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Hello,
I want to get the right most name of the a domain name, for example:
if the domain is www.myweb.com , I want to get myweb.com something.myweb .com --> myweb.com www.myweb.com.au --> myweb.com.au something.myweb .com.au --> myweb.com.au www.myweb.tv --> myweb.tv www.something.myweb.net --> myweb.net my.test.myweb.c a --> myweb.ca
I want to know if there is a general rule, code or article regarding this issue. I tried the following code, but I am not convinced, because it is not generic public static string GetDomainName(s tring serverName ) {
if(!serverName. Contains(".")) {
return serverName.ToLo wer();
}
if(serverName.E ndsWith(".co.uk ")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - ".co.uk".Le ngth - 1) + 1).ToLower();
}
if(serverName.E ndsWith(".com") || serverName.Ends With(".net") || serverName.Ends With(".org")) {
return serverName.Subs tring(serverNam e.LastIndexOf(" .", serverName.Leng th - 5) + 1).ToLower();
}
return null;
}
Does any one have a better solution? Adam Tibi
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Wm |
last post by:
I'm totally clueless on this one -- I'm getting 3 copies of every Email (in
plain text, not HTML as expected), from a single mail() line... Can anyone
tell me what might be causing the duplicates??
Thanx!
Wm
<?PHP
include('dbconn.php');
|
by: Buddy Ackerman |
last post by:
I have an application where the client wants AD integration. The application requires that the user accounts reside in
the app's database. The application is a (.NET) webservices based app where the desktop client polls a webservice to
return info to the user. The client wants to only manage accounts via the AD. So if they create a new AD user then the
app should automatically create a user in the app database. This is not such a problem...
|
by: Peter Afonin |
last post by:
Hello,
I have a simple client-side form that is checking the domain availability on
the domain registrar's server:
<FORM action="https://www.webnames.ru/scripts/RegTimeSRS.pl" method="post">
<input type="hidden" name="thisPage" value="pispCheckDomain">
<input type="hidden" name="username" value="test">
<input type="hidden" name="password" value="test">
domain_name: <input type="text" name="domain_name"><br>
|
by: Scott M. Lyon |
last post by:
I'm having some strange problems with a VB.NET application that I support.
The application currently uses SystemInformation.UserName() and
SystemInformation.UserDomainName() to determine who is logged in, and what
network domain they are logged into.
And for our environment here (logged into a domain), it seems to work just
fine.
|
by: paul |
last post by:
HI! I keep on getting this error and I have tried different things but I am
not sure how to send the expiring date.
The error that I am getting in Firefox 1.5 is
"Error: expires.toGMTString is not a function"
----------------------------------------------------
I have this in a .js file and in the head section.
| |
by: Michael Howes |
last post by:
I'm writing a utility to manage a machines *local* accounts in c#
I am getting all the users in a specific Group just fine but when I
want to get some of the information on each user from their Properties
collection I can't get the properties on some users.
For example, I get all the users that are part of my machines
Administrators Group. I get get the properties of the built in local
Administrator account and some local IT account,...
|
by: Per0 |
last post by:
Hi,
I have problem getting all domains. My code looks like:
_dirEntry.Path = "LDAP://RootDSE"
_strRootDomain = "LDAP://" & _dirEntry.Properties("rootDomainNamingContext").Value.ToString()
_dirEntry.Path = _strRootDomain
_dirSearch.SearchRoot = _dirEntry
_dirSearch.Filter = "(objectClass=domainDNS)"
_resultColl = _dirSearch.FindAll
|
by: Chris White |
last post by:
Here's my XML
<?xml version="1.0" encoding="UTF-8"?>
<results>
<status code="ok"/>
<report-bulk-users>
<row principal-id="23859115" type="user">
<login>muser@domain.com</login>
<name>My User</name>
<email>myuser@domain.com</email>
<manager>manager@domain.com</manager>
|
by: sbettadpur |
last post by:
hello
i am calling .exe file through my php script.
i.e. using exec or system command, i am running exe file that exe file will create on txt file which contains who has logged into domain(i.e. domain user name).
actually once i run exe file the generated file name is according to user itself
for eg if "xyz" is a domain user who logged into domain and if he access the php script (remember php script is calling exe file) the final...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |