Hi,

I Have a CString (MFC) which contains the following three conditions separated as follows.

Message=("Condition1|Condition2|Condition3")

I am trying to extract the three conditions from the CString and use them to perform other operations. However I cant seem to find the right built-in function.

Could someone please advise on what the best way to do this will be? Cant seem to find a function which can strip away to the left and right of the "|" operator.

Thanks in advance.

CString has Left(), Right(), and Mid() methods which are something like std::string's substr() method.

Thanks, stupid question i suppose...

I've always found AfxExtractSubString() to be useful for that kind of thing. Not a particularly well documented function but it's there and it works.

BOOL AFXAPI AfxExtractSubString (
   CString& rString,
   LPCTSTR lpszFullString,
   int iSubString,
   TCHAR chSep = '\n'
);

e.g.
set lpszFullString to "Condition1|condition2|Condition3",
set chSep to '|'
set iSubString to 0,1 or 2
and you'll get rString returned as "Condition1", "Condition2", or "Condition3".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.