1、按单字符分割
std::vector<CString CBOMAutoToolDlg::GetArrayFromCstringBySep( const CString & str, const TCHAR cSep)
{
CString CurrStr = str;
std::vector<CString> DataList;
int CurrPos;
while((CurrPos = CurrStr.Find(cSep)) != -1)
{
DataList.push_back(CurrStr.Left(CurrPos));
CurrStr = CurrStr.Right(CurrStr.GetLength()-CurrPos-1);
}
if (!str.IsEmpty())
{
DataList.push_back(str.Left(CurrPos));
}
return DataList;
}
2、按多个字符分割
//source为待分割字符串 如 "2014-6-17 上午 08:01:20",按" :-"分割,分割之后放入DataList中
CString division(_T(" :-"));
std::vector<CString> DataList;
TCHAR *pch1;
TCHAR *p1;
pch1 = wcstok_s(source.GetBuffer(), division, &p1);
DataList.push_back(CString(pch1));
while (pch1 != NULL)
{
pch1 = wcstok_s(NULL, division, &p1);
DataList.push_back(pch1);
}