Thread: c++ string

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    11

    c++ string

    How can I check that string name has at least one char, and has no char other than letters and hyphens?
    Especially the last part , how to check that it has just letters(either upper case or lower one) and no hyphens?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by chess2009 View Post
    How can I check that string name has at least one char, and has no char other than letters and hyphens?
    Especially the last part , how to check that it has just letters(either upper case or lower one) and no hyphens?
    To check if it's empty, use str.empty(), which returns true if it is empty and false if not. To check whether a string has any other characters, simply iterate through all of them and check them manually (isalpha), or use str.find_first_not_of().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM