tags:

views:

63

answers:

2

I am writing a method whose signature is

bool isValidString(std::string value)

Inside this method I want to search all the characters in value are belongs to a set of characters which is a constant string

const std::string ValidCharacters("abcd")

To perform this search I take one character from value and search in ValidCharacters,if this check fails then it is invalid string is there any other alternative method in STL library to do this check.

+4  A: 

Use find_first_not_of():

bool isValidString(const std::string& s) {
    return std::string::npos == s.find_first_not_of("abcd");
}
Georg Fritzsche
A: 

you can use regular expressions to pattern match. library regexp.h is to be included

http://www.digitalmars.com/rtl/regexp.html

That's D, not C++.
DeadMG
did you even go to the link and read the first line
@Dead: Although its overkill here: *"RegExp is a C++ class to handle regular expressions."*
Georg Fritzsche
It is C++, but there's no need to bring in a non-standard library just to throw regular expressions at a problem that doesn't need them
Mike Seymour
i know its over kill but it can be done.
@Crazy: To be entirely fair, I didn't read the link. I know that digitalmars is the site of the primary D compiler. There is, however, a regex header in TR1.
DeadMG