Thread: strings

  1. #1
    Registered User Bob Vila's Avatar
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5

    strings

    Hey guys,

    I need to know if someone can give me an example of how to check to see if an email address read from a text file has a "." between something like yahoo and com
    ex. yahoo.com compared to yahoocom
    and also how to insert one in if it dosent have one.

    Thanks,
    Bob

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Quote Originally Posted by Kermi3
    Welcome to the boards. If you haven't already done so then please take some time to familiarise yourself with the faq:
    http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

    Make sure you have a look at the the posting guidelines:
    http://cboard.cprogramming.com/annou...ouncementid=51
    Following the rules will ensure you get a prompt answer to your question.

    Remember, too, that the board has a search facility, a link is at the top of your screen:
    http://cboard.cprogramming.com/search.php
    It will often get you a quicker answer to your questions than waiting for a response to one you have posted.


    If you have any questions about this you may ask or you can contact one of our forum leaders:

    http://cboard.cprogramming.com/showgroups.php
    ^ ^ ^ ^
    Show us what you've got (or even thought of) so far, and we may be willing to help.
    Just Google It. √

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

  3. #3
    Registered User Bob Vila's Avatar
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5
    thx for the post, but I already seached all that stuff and was unsucessful in my search Maybe I'm just using the wrong terms or something...

    Show us what you've got (or even thought of) so far, and we may be willing to help.
    It's 3 files, and fairly big, but if you really want me to post I still can...

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Look in to the strstr function, or implement your own function.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I need to know if someone can give me an example of how to check to see if an email address read from a text file has a "." between something like yahoo and com
    ex. yahoo.com compared to yahoocom
    and also how to insert one in if it dosent have one.
    With website names like yahoo.com, partypoker.net, the dot is the fourth character from the end. So, if you read your website name into a string type, you can:

    1) Check to see if the 4th character from the end of your string is a '.' using array notation with the string variable

    2) if it is, then do nothing

    3) otherwise get the substr() up to the dot and put it a second string variable, add a '.' to the second string, and finally add the rest of the first string to the second string using substr( ) again.

    However, if there are going to be website extensions like:

    .aero, .coop, .info, .museum, .name

    then you will probably have to use a for loop to search the string for a '.', and if you don't find one, then check each possible extension against the end of the string.
    Last edited by 7stud; 03-05-2005 at 02:09 AM.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    This is a C++ board, and you mentioned string, so is it safe to assume you are talking about the C++ string class? If so, just use find() (or rfind()) to find the '.' and use substr() to separate the pieces.

  7. #7
    Registered User Bob Vila's Avatar
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5
    i've been messing with it most afternoon, and theoreticly this should work shouldn't it?
    Code:
     x = rj.email.length(); 
       y = ri.email.length(); 
    
       x -= 3; 
       y -= 3;
    
       if(rj.email.find('.'))
       rj.address.insert(x, ".");
    
       if(ri.email.find('.'))
       ri.address.insert(y, ".");
    it compiles fine, but i get this when i try running it
    http://geocities.com/bobvila2003/insert.JPG

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I believe you need to test the return value of find() for std::string::npos, instead of just testing for truth. Also, you should check to make sure that length() returns a value of at least 3, otherwise you'll get an array index out of bounds (you could be accessing array elements -3, -2 and -1). Also check just to make sure that length() is returning what you expect
    Just Google It. √

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

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What about ".info" sites? There are now domains that end in more than just three character suffixes.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by quzah
    What about ".info" sites? There are now domains that end in more than just three character suffixes.

    Quzah.
    The issue was already raised:
    However, if there are going to be website extensions like:

    .aero, .coop, .info, .museum, .name

    then you will probably have to use a for loop to search the string for a '.', and if you don't find one, then check each possible extension against the end of the string.

  11. #11
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I doubt this can be done at all, practically at least, unless it is a fixed 3 characters. Anyway, there's .nl and .tk etc. too.
    Just Google It. √

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

  12. #12
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I doubt this can be done at all, practically at least,
    Sure it can.

  13. #13
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    surely,one can find the '.' but inserting '.' is not that easy.one should then know all
    .com,.tk,.info etc sites .

  14. #14
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    http://data.iana.org/TLD/tlds-alpha-by-domain.txt

    A list of all the avaliable top level domains. You could look for combinations of these in the string, however if they have something like "myinfo.com", you'd end up with "my.info.com".

    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" and query that, rinse and repeat. However, the first match you find may still be incorrect.

    The you could go further. Take a string, "mycoukinfocomau", find every possible match in the string, query them all, and if more than one matches ask the user.

    Finding the '.' is easy - can be done with one for loop. But finding where one should be is far harder. If you can find a way, let me know.

  15. #15
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    I haven't written C++ for years, but heres how I'd do it in C#, maybe it would help (untested).
    Code:
    void main()
    {
    	// This holds a list of all the possible top level domains (tlds)
    	StringCollection tlds = new StringCollection();
    
    	using (StreamReader reader = new StreamReader("top-level-domains.txt"))
    	{
    	 	while ((string s = reader.ReadLine()) != null)
    	 	{
    	 	 	// Loop through and add each TLD to the top level domains collection
    	 	 	tlds.Add(s.Trim().ToLower());
    	 	}
    	}
    
    	// This collection holds all our inputs
    	StringCollection emails = new StringCollection();
    
    	using (StreamReader reader = new StreamReader("emailList.txt"))
    	{
    	 	while ((string s = reader.ReadLine()) != null)
    	 	{
    	 	 	// Loop through and add each email to the collection
    	 	 	emails.Add(s.Trim().ToLower());
    	 	}
    	}
    
    	foreach (string email in emails)
    	{
    		foreach (string match in GetMatches(email))
    		{
    			Console.WriteLine("Match: " + match);
    		}
    	}
    }
    
    StringCollection GetMatches(string email)
    {
    	StringCollection results = new StringCollection();
    	// test for the dot, im sure you can do that
    	[..]
    	// else test without a dot
    	oh i cant be stuffed
    }

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