#include "stdafx.h"
#include <string>
#include <vector>
int split(std::string pszSrc, const char* flag, std::vector<std::string>& vecDat)
{
if (pszSrc.empty() || !flag)
return -1;
std::string strContent, strTemp;
strContent = pszSrc;
std::string::size_type nBeginPos = 0, nEndPos = 0;
while (true)
{
nEndPos = strContent.find(flag, nBeginPos);
if (nEndPos == std::string::npos)
{
strTemp = strContent.substr(nBeginPos, strContent.length());
if (!strTemp.empty())
{
vecDat.push_back(strTemp);
}
break;
}
strTemp = strContent.substr(nBeginPos, nEndPos - nBeginPos);
nBeginPos = nEndPos + strlen(flag);
vecDat.push_back(strTemp);
}
return vecDat.size();
}
参考:https://blog.csdn.net/wu110112/article/details/88222137
|