1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
CArray<int,int> result;
std::string str1="1,25,35,46,60";
std::string str2=",";
stringSplitToInt(str1, str2,&result);
//....
void CTestDlg::stringSplitToInt(std::string str, std::string delim, CArray<int,int> *results)
{
int cutAt;
while( (cutAt = str.find_first_of(delim)) != str.npos )
{
if(cutAt > 0)
{
std::string tmp = str.substr(0,cutAt);
const char* tmp2 = tmp.c_str();
int tmp3 = atoi(tmp2);
(*results).Add(tmp3);
}
str = str.substr(cutAt+1);
}
if(str.length() > 0)
{
(*results).Add(atoi(str.c_str()));
}
} |
Partager