CString分割切分

说明:CStringArray只能用引用传入,不可以作为函数返回值,因为CStringArray集成的CObject不支持复制构造

void SplitCString(const CString& _cstr, const CString& _flag, CStringArray& _resultArray)
{
CString strSrc(_cstr);

CStringArray& strResult = _resultArray;
CString strLeft = _T("");

int nPos = strSrc.Find(_flag);
while(0 <= nPos)
{
strLeft = strSrc.Left(nPos);
if (!strLeft.IsEmpty())
{
strResult.Add(strLeft);
}
strSrc = strSrc.Right(strSrc.GetLength() - nPos - 1);
nPos = strSrc.Find(_flag);
}

if (!strSrc.IsEmpty()) {
strResult.Add(strSrc);
}
}

posted @ 2019-01-18 22:10  kuaqi  阅读(1401)  评论(0编辑  收藏  举报