VC:分割字符串

void CTestTelnet2Dlg::Split(CString source, CStringArray &dest, CString div)
{
	
	dest.RemoveAll();
	CString tmp;
	int start = 0;
	int pos;
	do{
		pos = source.Find(div,start);
		if(pos!=-1)
			tmp = source.Mid(start,pos-start);
		else tmp = source.Mid(start);
		start = pos+1;
		if(0!=tmp.GetLength())
			dest.Add(tmp);
	}while(pos!=-1);
	
}

posted on 2011-03-10 21:02  yangyh  阅读(336)  评论(0)    收藏  举报