strings and how to check for spesific chars?

Mar 18, 2012 at 9:04am
Hey I have been trying to find a food and ofisont way of checking to see if a string contains a certen set of characters.
So if I got a string s1 = "hello" and s2 = "hellu".
I want to check to see if check to see
if s1 got "h, e, l, o" is dose print it. s2 got some but not all and it got 'u' that's not a wanted character so we disregard it.

Do anyone know of a way to do this?
Any help is greatly appreciated.
Cheers
WetCode
Mar 18, 2012 at 9:48am
1
2
3
string s1="hello", s2="hellu", test="helo";
if (s1.find_first_not_of(test)==string::npos) cout<<s1;
if (s2.find_first_not_of(test)==string::npos) cout<<s2;

It will print only s1, becouse s2 doesn't contain all of the characters in test.
Mar 18, 2012 at 10:06am
So if the string do not contain atlest 1 of all the characters in test it will not be printed?

What I want to do is check to see if it got some characters but it may not be an 'h' but just "elloo" I stile would want to print that string out, but if it contains an character I didn't put in test like '1' its not getting printed.

Sorry for being a bit slow here..
Appreciat your help.

Cheers
Last edited on Mar 18, 2012 at 10:17am
Topic archived. No new replies allowed.