CString分割切分 实现SplitCString

来源:互联网 发布:数据库集群方案 编辑:程序博客网 时间:2024/06/06 23:52

直接上代码

说明: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);}}


原创粉丝点击