直接上代码
说明: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);
}
}
本文介绍了一种使用 CStringArray 在 C++ 中进行字符串分割的方法。该函数通过指定分隔符来分割字符串,并将结果存储在一个引用传递的 CStringArray 对象中。注意由于 CObject 的限制,CStringArray 不能作为函数的返回值。
667

被折叠的 条评论
为什么被折叠?



