0

I know how to use the compare functions to check if a string is exactly the same as another but I wasn't sure if there is an easy way to go about checking if a string contains any sequence of A through F. Can I add up the memory values of A through F and then add them up for whatever variant on them is passed and see if those two values are equal? Thanks for your help.

Edited by twicepipes: n/a

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by vijayan121
0

Now when you say any sequence of A-F do you mean you are only checking 6 characters sized strings like ABCDEF, ACBdEF, ACDBEF, .... If that is the case then something like this should do the trick.

string sequence = "ABCDEF"
string random; // has a random mix of "ABCDEF";
string tester = random;
sort(tester.begin(), tester.end());
if (sequence == tester)
    cout << "has ABCDEF"
else
    cout << "Does not have ABCDEF";

If you are checking a string to see if all of the charactures in it are only A-F then you can use the find_first_not_of() function like this.

string random  = "ABCCCDEFFFABC";
if (random.find_first_not_of("ABCDEF") == string::npos)
    cout << "has only ABCDEF"
else
    cout << "Does not have only ABCDEF";

Edited by NathanOliver: n/a

0

> Can I add up the memory values of A through F and then add them up
> for whatever variant on them is passed and see if those two values are equal?

No. (why?)

One way is to use the == operator of std::set<>

std::string str = "vjjjJGJGJGJgjjVHhACDBFEfhyffhyfhyfhyf" ;
const std::set<char> abcdef = { 'A', 'B', 'C', 'D', 'E', 'F' } ;

for( auto iter = str.begin() ; iter < str.end() - abcdef.size() + 1 ; ++iter )
{
     if( std::set<char>( iter, iter+abcdef.size() ) == abcdef )
     {
         // found it
     }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.