Split functionality for MFC Cstring Class

Dharma picture Dharma · Jun 30, 2010 · Viewed 60.7k times · Source

How to Split a CString object by delimeter in vc++?

For example I have a string value

"one+two+three+four"

into a CString varable.

Answer

sje397 picture sje397 · Jun 30, 2010

Similar to this question:

CString str = _T("one+two+three+four");

int nTokenPos = 0;
CString strToken = str.Tokenize(_T("+"), nTokenPos);

while (!strToken.IsEmpty())
{
    // do something with strToken
    // ....
    strToken = str.Tokenize(_T("+"), nTokenPos);
}