如何在下面的字符串中获取data="
和"
之间的所有字符串?谢谢!
L"list c s data=\"vi\" c c s data=\"việt nam\" c c s data=\"việt nam ơi\" list"
//vi
//việt nam
//việt nam ơi
答案 0 :(得分:1)
#include <string>
#include <algorithm>
#include <iostream>
#include <iterator>
/*
*
*/
int main(int argc, char** argv) {
std::string beg("data=\"");
std::string en("\"");
std::string s("list c s data=\"vi\" c c s data=\"việt nam\" c c s data=\"việt nam ơi\" list");
std::string::iterator itBeg = s.begin();
std::string::iterator itEnd;
while(s.end() != (itBeg = std::search(itBeg, s.end(), beg.begin(), beg.end()))) {
itEnd = std::search(itBeg + beg.size(), s.end(), en.begin(), en.end());
std::string word;
std::copy(itBeg + beg.size(), itEnd, word.begin());
std::cout << "Word:" << word.c_str() << std::endl;
itBeg = itEnd;
}
return 0;
}
词语:六
Word:việtnam
Word:việtnamami