473,325 Members | 2,774 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,325 software developers and data experts.

Removing subdomains from a string

Hi

Could anyone give me some pointers on how to remove subdomains from a string?

For example:
  • If the string was bytes.com, it would stay bytes.com
  • If it was subdomain.bytes.com, it would become bytes.com
  • If it was subsubdomain.subdomain.bytes.com, it would become bytes.com

Essentially, it just needs to strip off the subdomains and produce the root domain if not already present.

Cheers
akadeco
Sep 11 '09 #1
3 6622
micmast
144 100+
I would suggest explode the string and always take the last 2 values of the returned array.
Sep 11 '09 #2
bvdet
2,851 Expert Mod 2GB
To clarify micmast's suggestion, I believe he means split instead of explode.

Expand|Select|Wrap|Line Numbers
  1. >>> s = 'bytes.com'
  2. >>> '.'.join(s.split('.')[-2:])
  3. 'bytes.com'
  4. >>> s = 'subsubdomain.subdomain.bytes.com'
  5. >>> '.'.join(s.split('.')[-2:])
  6. 'bytes.com'
  7. >>> 
Sep 11 '09 #3
micmast
144 100+
bvdet, yes you are right :) explode is php syntax.

sorry.
Sep 11 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: steve | last post by:
Hi I am writing an application which ideally requires the creation of subdomains dynamically via asp. However I want all the subdomains to point to 1 asp file, which I wish to use to figure out...
3
by: craigkenisston | last post by:
In an application I'm developing I will be using subdomains in the main website to hold some sections of the sites. There will be many serverside generated links that will point to this...
2
by: craigkenisston | last post by:
Hi, I create a one day ticket in my authentication code like this : private void btnLogin_Click(object sender, System.EventArgs e) { string _userId = txtUserId.Text; string _password =...
4
by: radiax | last post by:
Is there a way to associate or bind a subdomain to a tcp sockets under .net framework (vb.net / c#). I know ip address can be used when using sockets, but the problem is the ip address is shared...
1
by: Hans Kesting | last post by:
Hi, Is it possible to share sessions between subdomains? Say: the user logs in at www.company.com, and is redirected to my.company.com. This is a different url for the same application. Can I...
8
by: Kenny Lai | last post by:
hey, Is there a way to communicate between iframes on different subdomains? e.g. from one.dot.com to two.dot.com? there is a security access restriction passing javascript commands between...
1
by: onequestion | last post by:
Hi friends.. Is it possible to find subdomains on a domain. Can someone help me? currently i'm using this code.. private static String GetSubDomain(URL url) ...
9
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept...
3
by: Jonathan Wood | last post by:
Perhaps someone who understand Web hosting can offer some insight into this. I have several sites hosted at http://www.crystaltech.com. There were highly recommended and seem pretty good. But...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.