String shaping
# include & lt string & gt

# include & ltstdlib.h & gt

# include & ltiostream & gt

Use namespace std

/*

String to number

*/

int s2i(const char * str,int *num)

{

int I;

* num = 0;

if (strlen(str) == 0)

{

return- 1;

}

for(I = 0; I & ltstrlen(str);); i++)

{

if(*(str+I)& lt; 0 ' | | *(str+I)>;' 9')

{

return- 1;

}

* num =(* num)* 10+(*(str+I))-' 0 ';

}

Returns 0;

}

/*

String segmentation method

Divide str into string array pStr with separator',', and subStrCount is the number of separated strings.

*/

int splitString(string str,string **pStr,int *subStrCount)

{

int strLen = str . length();

int pLen =(strLen+4)/4 * 4;

char * p source = new char[pLen];

char * p;

memset(pSource,0,pLen);

memcpy(pSource,str.c_str(),str . length());

(* sub count)= 0;

for(int I = 0; I & ltstrLeni+++)

{

if (*(pSource + i) = ',')

{

(* sub count)++;

*(p source+I)= 0;

}

}

//The string does not end with a delimiter (there is a string after the last delimiter)

if (*(pSource + strLen - 1)! = ',')

{

(* sub count)++;

}

*pStr = new string [* (substrcount)];

p = pSource

for(int I = 0; I<* subStrCounti++)

{

(* pStr)[I]= p;

p += (*pStr)[i]。 Length ()+1;

}

Returns 0;

}

int _tmain(int argc,_TCHAR* argv[])

{

string strTest = " 12,4,52 1 ";

string * pStr = NULL

int * numbs = NULL

Int sub-count;

split string(strTest & amp; pStr & amp; sub count);

if(substr count & lt; = 0)

{

return- 1;

}

numbs = new int[substr count];

for(int I = 0; I < sub-count; i++)

{

s2i(pStr[i].c_str(),(numbs+I));

}

for(int I = 0; I < sub-count; i++)

{

cout & lt& lt*(numbs+I)& lt; & lt" ";

}

cout & lt& ltendl

if (pStr! = empty)

{

Delete [] pstr;

pStr = NULL

}

If (numb! = empty)

{

Delete [] digits;

numbs = NULL

}

Returns 0;

}