網(wǎng)站代碼修改某個(gè)產(chǎn)品營銷推廣方案
?匹配一個(gè)字符串buf中,連續(xù)包換運(yùn)算符reg的次數(shù):
#include <iostream>//return 返回匹配的字符個(gè)數(shù)
//buf, 要檢測的字符串
//reg, 包含的連續(xù)運(yùn)算符
int GetMatchCount(std::string& buf, std::string& reg)
{int nMatchCount = 0;if (reg.empty())return nMatchCount;std::string matchReg = reg;for (int i = 0; i < buf.length(); i++){if (buf[i] == matchReg.front()){matchReg.erase(matchReg.begin());}if (matchReg.empty()){nMatchCount ++;matchReg = reg;}}return nMatchCount;
}
使用示例:
int main()
{std::string text = "[][][[(Hello World!)]";std::string reg = "[]";std::cout << "match string:\"" << text << "\" | reg(\"" << reg << "\")" << std::endl;int count = GetMatchCount(text, reg);std::cout << "match count: " << count << std::endl;return 0;
}
運(yùn)行結(jié)果: