//由于读取到的字符串是以逗号分隔,现要分别获取以逗号分隔的每个数值(以字符串形式存储),思路如下:
1.查找一个字符串中逗号的个数函数:
//查找str中‘,’的个数
int findCharCount(CString str)
{
int num=0;
char* strchar = (char *)malloc(sizeof(char));//初始化strchar
strchar=(LPSTR)(LPCTSTR)str;//将str转换成char*
for (int i=0;i<str.GetLength();++i)
{
if (strchar[i]==',')
{
++num;//如果为逗号,num加1
}
}
strchar=NULL;
return num;
}
2.分别获取以逗号相隔的数值(字符串形式),代码如下:
int count=findCharCount(childmv);//count为childmv中逗号的个数
CString child_id;//保存输出的字符串
for (int j=0;j<count;++j)
{
//AfxExtractSubString函数用于分割字符串,第一参数保存输出的字符串,
//第二个参数为待分割的字符串,第三个参数为提取的字符串的序号,从0开始
//第四个参数为用于分割的字符,默认为‘\n’
AfxExtractSubString(child_id,childmv,j,',');//child_id保存着每一个以逗号分隔的数值(字符串形式)}
//AfxExtractSubString(child_id,childmv,j,',');之后再添加对获取的每一个数值进行处理的代码