您的位置:首页 > 其它

CString分割切分 实现SplitCString

2017-06-27 19:23 190 查看
直接上代码

说明: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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: