How do I detect a quoted substring in a string?
am trying to determine if a string contains a quoted substring.
This is my code that gives me a compile error: "ai3.cpp:162:37: warning: character constant too long for its type"
Code:
//if the line contains 'class="wikitable"'
string findString = 'class="wikitable"';
size_t pos = str.find(findString);
if (pos != string::npos) {
cout << "Substring found at position " << pos << endl;
}
I've tried:
Code:
"'class=\"wikitable\"'"
but str.find doesn't find my substring.
So, can anyone suggest how I may search for the presence of a quoted substring?
Re: How do I detect a quoted substring in a string?
And what does the str.find return?
Re: How do I detect a quoted substring in a string?
> This is my code that gives me a compile error: "ai3.cpp:162:37: warning: character constant too long for its type"
The outer string needs to be in double quotes, and the inner ones escaped.
Like so
Code:
string findString = "class=\"wikitable\"";
This isn't Python, where '' and "" are equivalent.
Re: How do I detect a quoted substring in a string?
or you can use raw strings
Code:
#include <iostream>
#include <string>
int main() {
const std::string findString { R"(class="wikitable")" };
std::cout << findString << '\n';
}
which displays: