vector<string> splitStr(const string &str, char seoperator)
{
int iSize = str.size();
if (iSize == 0) return vector<string>(0);
int iCount = count(str.begin(), str.end(), seoperator);//根据换行符号个数,初始化容器最长度
vector<string> retVct(iCount);
int index = 0, iFront = 0, iRear = 0;
for (; iRear < iSize; ++iRear)
{
if (str[iRear] == seoperator)
{
if (iFront == iRear)
{
++iFront;
retVct[index++] = "";
continue;
}
retVct[index++] = str.substr(iFront, iRear - iFront);
iFront = iRear + 1;
}
}
if (str[iSize - 1] != seoperator)
{
retVct.push_back(str.substr(iFront));// 文件末尾可能无换行符,避免越界,增加一个
}
return retVct;
}
vector<string> splitStr(const string& str, const string& strSeparator)
{
vector<string> vctRet;
int iPosFront = 0;
int iPosRear = str.find(strSeparator);
const int iStepSize = strSeparator.size();
while (iPosRear != -1)
{
vctRet.push_back(str.substr(iPosFront, iPosRear - iPosFront));
iPosFront = iPosRear + iStepSize;
iPosRear = str.find(strSeparator, iPosFront);
}
vctRet.push_back(str.substr(iPosFront));
return vctRet;
}