首先,分离出一个一个字符串
CString cstrTemp = "12,-12,13";
CString cstrSplit = ",";
CString cstrData("");
int nIndex=0, nCnt=0;
while (TRUE)
{
nIndex = cstrTemp.Find(cstrSplit);
if(nIndex == -1)
{
acstrRet.Add(cstrTemp);
nCnt++;
return nCnt;
}
else
{
cstrData = cstrTemp.Left(nIndex);
cstrTemp = cstrTemp.Right(cstrTemp.GetLength() - (nIndex + cstrSplit.GetLength()));
acstrRet.Add(cstrData);
nCnt++;
}
}然后,将每个字符串转换为数值,也就是逐个将'0'...'9'转换为0...9
CString cstrTemp = "12,-12,13";
CString cstrSplit = ",";
CString cstrData("");
int nIndex=0, nCnt=0;
while (TRUE)
{
nIndex = cstrTemp.Find(cstrSplit);
if(nIndex == -1)
{
acstrRet.Add(cstrTemp);
nCnt++;
return nCnt;
}
else
{
cstrData = cstrTemp.Left(nIndex);
cstrTemp = cstrTemp.Right(cstrTemp.GetLength() - (nIndex + cstrSplit.GetLength()));
acstrRet.Add(cstrData);
nCnt++;
}
}然后,将每个字符串转换为数值,也就是逐个将'0'...'9'转换为0...9
或
strTok atol;
token = strtok( string, ",");
while( token != NULL )
{
/* While there are tokens in "string" */
atol(token );
/* Get next token: */
token = strtok( NULL, "," );
}