void Ctest11View::SplitStrToArr(CString str,TCHAR chSep,CStringArray *arr)
{
CString strTmp = str;
int nSepCount=strTmp.Replace(chSep,'a');//得到分割符的数量
CString strGet=_T("");
int i = 0;
while(i < (nSepCount + 1))
{
AfxExtractSubString(strGet,str,i, chSep);
arr->Add(strGet);
i++;
}
}
好像CStringArray不能向函数传参数,要先new一个指针。
测试:
CStringArray *arr = new CStringArray();
CString str = _T("2,3,4,5");
SplitStrToArr(str,',',arr);
//arr->RemoveAll();
MessageBox(arr->GetAt(3));
delete arr;