CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Finding Consecutive Chars in a String

    I'm trying to write an email validation program, and I'm having a lot of trouble finding a way to check a string for invalid consecutive chars. Specifically, emails cannot have a repeated ".", "-", or combination of these two chars, so email-.@abc.com is invalid.

    Does anyone have any ideas on how I could approach this? In particular, the "-." and ".-" possibilities are messing me up.

    Any help would be appreciated!

    Thanks,
    --valhalla8

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Finding Consecutive Chars in a String

    Read the string one character at a time. Compare the current character to the next character until you find an invalid match or you run out of characters.

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Finding Consecutive Chars in a String

    Personally, I'd probably just strstr() it (or string::find() it) for each invalid possibility at a time. Slightly less efficient, but easier.

  4. #4
    Join Date
    Feb 2010
    Posts
    2

    Re: Finding Consecutive Chars in a String

    Thanks a lot guys. I tried to do the first way but I'm retarded so I couldn't figure it out without making a huge nested for/if loop, so I'll probably have to stick with the second way and hope my professor finds it acceptable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured