Thread: strings

  1. #16
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    ...and now it has been done. I wrote a program of about 60 lines, and it adds a dot before extensions of any length. Works like a charm.

    surely,one can find the '.' but inserting '.' is not that easy.one should then know all
    .com,.tk,.info etc sites .
    Well, if you don't know what you are checking for, then I guess that would be a problem.

    Finding the '.' is easy - can be done with one for loop.
    Why would you ever need to find a dot? It seems to me, the poster wants to correct faulty email addresses that don't have dots separating the extension from the rest of the email address.

    But finding where one should be is far harder
    That is what the question is.

    however if they have something like "myinfo.com", you'd end up with "my.info.com".
    With the program I wrote, if you start with "myinfocom", you end up with "myinfo.com", and if you start with "myinfo.com" you end up with no change.
    Last edited by 7stud; 03-07-2005 at 05:57 AM.

  2. #17
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Quote Originally Posted by 7stud
    Why would you ever need to find a dot? It seems to me, the poster wants to correct faulty email addresses that don't have dots separating the extension from the rest of the email address.
    Read the original question. There were two parts to it.

    Post your code. I bet my left testicle it's not going to get the exact email the user wanted every time. There are just too many variances to consider. The best you could get is an educated guess.

  3. #18
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Read the original question. There were two parts to it.
    Possibly. The poster would have to clarify what he wants the program to produce for each of the two strings:

    yahoo.com
    yahoocom

    In the first case, I assumed he wanted there to be no change.

    Post your code.
    I think Bob Vila is still working on the problem. Here is an example of my output, though:
    Code:
    myinfo.com
    myinfocom---->myinfo.com
    yahoocom---->yahoo.com
    excite.com
    partypokernet---->partypoker.net
    govnl---->gov.nl
    editplus.info
    cplusplusinfo---->cplusplus.info
    Press any key to continue
    Last edited by 7stud; 03-07-2005 at 06:07 AM.

  4. #19
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    You could cheat by getting one TLD (ie ".au"), querying the site to see if it returns a match, and if not cycle through again for another extension ".com.au"
    If your scepticism is based on email addresses with a double extension like .com.au, then you are right my program doesn't address those. I used the poster's example of "yahoocom" as my model.
    Last edited by 7stud; 03-07-2005 at 06:24 AM.

  5. #20
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Quote Originally Posted by 7stud
    If your scepticism is based on email addresses with a double extension like .com.au, then you are right my program doesn't address those. I used the poster's example of "yahoocom" as my model.
    Thats a fair reasoning. I couldn't see how you could do it for multiple domain extensions and get it right 100%, but you are correct, it depends on what the OP expects the input to be.

  6. #21
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Ok, I'll tell my copyright lawyer to cancel filing the paperwork.

  7. #22
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Quote Originally Posted by 7stud
    Ok, I'll tell my copyright lawyer to cancel filing the paperwork.
    Were you going to patent your solution?

  8. #23
    Registered User Bob Vila's Avatar
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5
    I think Bob Vila is still working on the problem.
    i was able to figure out my problem with the inserting

    it is just for a programming competition, and all the sample data has is .com or .org ect. that is why i was only doing 3 chars. though the data that they test it with might have other emails.

    thanks for all the help guys

  9. #24
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>Sure it can.
    If domains (I'm assuming that's what '.com' etc. are called) are exclusive from right to left, then it can. If this is not the case, however, then:

    www.abcdefg.hij
    www.abcdefgh.ij

    If you are given www.abcdefghij, then you will find two different possible domains. On the other hand, if it is guaranteed that domains will not overlap from right to left (i.e. [.com and .comp] are allowed but [.com and .acom] are not), then you can iterate the string backwards eliminating all domains that do not match until you have one string remaining. The same cannot be said if domains are only guaranteed not to overlap from left to right.

    Code:
    list<string> domainList;
    
    //dottify() returns true if a unique match was found and the URL has been dotted.
    bool dottify(string& s)
    {
       list<string> potentialDomains = domainList;
    
       //Iterate backwards, checking each character with the domains.
       for(string::size_type i = 1; i <= s.size(); ++i)
       {
          list<string>::iterator it = potentialDomains.begin();
    
          //Check the corresponding character in each domain
          while(it != potentialDomains.end())
          {
             if(it->size() < i)  //Domain is too short
             {
                it = potentialDomains.erase(it);
                continue;
             }
    
             if((*it)[it->size() - i] != s[s.size() - i])  //Character doesn't match
             {
                it = potentialDomains.erase(it);
                continue;
             }
    
             ++it;
          }
    
          if(potentialDomains.size() == 1)   //If only 1 domain matches, see if it works.
          {
             if(potentialDomains.front().size() > s.size())  //Domain is too long
                return false;
    
             s.insert(s.size() - potentialDomains.front().size(), 1, '.');
             return true;
          }
          else if(potentialDomains.size() == 0)
             return false;
       }
    
       return false;
    }
    Note that this is untested, and also that I'm working off the assumption that domains are right-to-left exclusive (gee, I'm making up a lot of words lately..).
    Last edited by Hunter2; 03-07-2005 at 06:15 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM