为什么经常在dest.add(strtmp)时,程序异常退出,无任何提示?
void Split(CString source, CString division, CStringArray& dest)
{
dest.RemoveAll();
int pos =0;
int pre_pos =0;
int dlen=division.GetLength();
CString strtmp;
while( -1!= pos ){
pre_pos = pos;
pos = source.Find(division,pos);
if(pos>=0 ){
strtmp=source.Mid(pre_pos,(pos-pre_pos));
//strtmp.ReleaseBuffer();
if(strtmp.GetLength()>0){
//MessageBox(NULL,strtmp,"字符串add前",0);
dest.Add(strtmp);
//MessageBox(NULL,strtmp,"字符串add后",0);
}
pos+=dlen;
}
else{
pos=source.GetLength();
if(pos>pre_pos){
strtmp=source.Mid(pre_pos,(pos-pre_pos));
//MessageBox(NULL,strtmp,"最后字符串",0);
if(strtmp.GetLength()>0)
dest.Add(strtmp);
}
pos=-1;
}
}
}