Since the read string is separated by commas, each value separated by a comma is now stored as a string, as follows: 1. Find the number of commas in a string:
Find the number of ', ' in str
int findcharcount (CString str)
{
int num=0;
char* Strchar = (char *) malloc (sizeof (char));//Initialize Strchar strchar=
(LPSTR) (LPCTSTR) str;//converts str to char* for
( int I=0;I<STR. GetLength (); ++i)
{
if (strchar[i]== ', ')
{
++num;//if comma, num plus 1
}
}
strchar=null;
return num;
}
2. Get the values separated by commas (in string form), and the code is as follows:
int Count=findcharcount (CHILDMV);//count is the number of commas in CHILDMV CString
child_id;//Save the output string for
(int j=0;j< COUNT;++J)
{The
//afxextractsubstring function is used to split the string, the first parameter holds the output string,
//The second argument is the string to be separated, and the third parameter is the ordinal of the extracted string, starting from 0
//The fourth parameter is for the split character, the default is ' \ n '
Afxextractsubstring (Child_id,childmv,j, ', ');//child_id holds each comma-delimited number (string form)}
Afxextractsubstring (Child_id,childmv,j, ', '), and then add the code to process each of the obtained values