L
Lars Schouw
How do I elegantly match the first chars in an STL string?
this works but is not very elegant.
#include <string>
#include <iostream>
void main()
{
using namespace std;
string str("ABCabc");
if (str.substr(0, 3).find("ABC") != string::npos)
cout << "match" << endl;
if (str.substr(0, 2).find("AB") != string::npos)
cout << "match" << endl;
if (str.substr(0, 2).find("bc") == string::npos)
cout << "no match" << endl;
}
Lars
this works but is not very elegant.
#include <string>
#include <iostream>
void main()
{
using namespace std;
string str("ABCabc");
if (str.substr(0, 3).find("ABC") != string::npos)
cout << "match" << endl;
if (str.substr(0, 2).find("AB") != string::npos)
cout << "match" << endl;
if (str.substr(0, 2).find("bc") == string::npos)
cout << "no match" << endl;
}
Lars