背景:需要从字符串中取出所有整数,暂不考虑负数。
CString strText = _T("1/2/17/18");
vector<CString>& vNumList;
const char* pText = strText.GetBuffer(strText.GetLength());
CString strTemp = _T("");
while (*pText != '\0')
{
if (*pText >='0' && *pText <= '9')
{
strTemp += *pText;
}
else if (!strTemp.IsEmpty())
{
vNumList.push_back(strTemp);
strTemp = _T("");
}
pText++;
}
if (!strTemp.IsEmpty())
{
vNumList.push_back(strTemp);
}