Friday, July 3, 2009

Su dung strtok in C++

bool checkStatus = false;

//wstring strSelAddrListTemp = SysAllocString(SelAddrList);
//char* charSelAddrList = new char[strSelAddrListTemp.length() + 1];
//wsprintfA(charSelAddrList, "%S", strSelAddrListTemp.c_str());
StringUtil *strSelAddrListTemp = new StringUtil();
*strSelAddrListTemp += ConvertBSTRToString(SelAddrList);

wstring strAddressTemp = SysAllocString(Address);
char* pch1 = new char[strAddressTemp.length() + 1];
wsprintfA(pch1, "%S", strAddressTemp.c_str());

char* pch;

//pch = strtok(charSelAddrList, ",");
pch = strtok((char*)strSelAddrListTemp ->data(), ",");

int position = 0;
while (pch != NULL)
{
if (stricmp(pch, pch1) == 0)
{
checkStatus = true;
break;
}
pch = strtok (NULL, ",");
position++;
}

//free memory
//delete charSelAddrList;
strSelAddrListTemp ->freeBuf();
delete pch1;

No comments: