Question:
C++ so i need to parse an email domain into subdomains...?
Mary Jean
2009-03-27 18:28:18 UTC
Alright I need some help getting started on this. I need to parse an email domain into subdomains...

now i know how to parse. if we needed to split yahoo.com into 'yahoo' and 'com' im totally good

but what if it is like apples.farm.land.com? how do i declare variables for 'apples' 'farm' 'land' and 'com'? There can be up to 64 subdomains in a working email address so seriously 64 variables aint happening :P any help just to get me in the right track would help...! THANKS
Six answers:
anonymous
2009-03-27 18:53:03 UTC
Count how many periods there are after the @ in the string. Use it to create the bounds in an string array variable.

Parse the domain and subdomains into the array in order from left to right so that you can reference the domain as the last value in the array.



In vb.NET there is a split function that returns an array based on a string and a character used to split the string into the array. I'm not sure if C++ has such a function but ideally, you want to write your own split function.
anonymous
2009-03-27 18:43:24 UTC
Only up to 64 characters in the domain part, not domains. And this does not always work. A subdomain is a lower level of the main domain, so :

the.low.level.co.uk is actually the :

.uk (TLD)

.co.uk

.level.co.uk

low.level.co.uk, possibly also the.low.level.co.uk, but this might only be the host name of one machine, which means the domain is still low.level.co.uk, and the machine name is the

Of course it may also have a CNAME of www in which case the same machine is going to be called :

www.low.level.co.uk

Not so simple. It depends on what use you need to make of this. As you see above not all the name would be valid for email.
anonymous
2009-03-27 19:19:21 UTC
Sorry if this doesn't help much, but here goes.

In PHP (the web language), there's a function called explode();, which takes a string you specify (like the . that separates sub domains), and separates anything between that character in the string into an array.

For example, the string "Hello. I am answering a question." would be exploded into:

Array[0]: "Hello"

Array[1]: "I am answering a question"



If you can find something similar in C++, it should do the trick. You could use a for loop and the count() method to pull the data out after.

Once again, sorry if this doesn't help.
alakit013
2009-03-27 19:03:39 UTC
Use vector and push there every text sub-part between dots.
anonymous
2009-03-27 18:32:03 UTC
Use an array of strings.
anonymous
2009-03-27 18:59:12 UTC
HASHISH MAP!



(i meant hash map)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...