1.
CString strAll;
strAll = "dialogWidth=600;dialogHeight=400;dialogLeft=100;dialogTop=100;maxable=1";
vector<CString> vecPara;
SplitString(vecPara,strAll,';');
CString strName,strValue;
map<CString,CString> mapParams;
for(std::vector<CString>::iterator pos=vecPara.begin();pos!=vecPara.end();++pos)
{
CString strAll = *pos;
ExtractSubString(strName,strAll,0,'=');
ExtractSubString(strValue,strAll,1,'=');
mapParams.insert(std::make_pair(strName,strValue));
}
for(map<CString,CString>::iterator iter=mapParams.begin();iter!=mapParams.end();++iter)
{
CString strTmp = (*iter).second;
MessageBox(strTmp);
}
2.
void CsplitDlg::SplitString(vector<CString> &strString,const CString &strFullString,
TCHAR chSep /*= '\n'*/)
{
CString str = strFullString;
TCHAR* token = _tcstok( str.GetBuffer(), &chSep);
str.ReleaseBuffer();
while( token != NULL )
{
strString.push_back(token);
token = _tcstok( NULL, &chSep );
}
}
3.
bool CsplitDlg::ExtractSubString(CString& strString,const CString &strFullString,
int iSubString, TCHAR chSep/* = '\n'*/)
{
int i=0;
CString str = strFullString;
TCHAR* token = _tcstok( str.GetBuffer(), &chSep);
str.ReleaseBuffer();
while( token != NULL )
{
if (iSubString==(i++))
{
strString = token;
return TRUE;
}
token = _tcstok( NULL, &chSep );
}
return FALSE;
}