A Generalized Parsing Class for MFC
Posted
by Richard Stringer
on March 2nd, 1999
The class is very simple to use. All that you need to provide is a data string to be parsed and a set of delimiters that seperate the various fields. In the above case that would be:
The class is really brain dead to use. Below is a sample of the code used in the demo to parse user input strings:
void CMainView::OnBtnparse()
{
CParseIt parser; // create a parser object
CString TheData; // place to put field data into
UpdateData(); // Get it current
if(!parser.Parse(m_Data,m_Seperator)) // this does all the work
return; // if here null string passed
InitList(); // empty current data from list ctrl
for ( int y=0; y < parser.GetNumFields();++y) // loop thru getting all the data
{
parser.GetField(y+1,TheData);
AddItemToList(y+1,TheData); // add it to the list
}
}
There are also functions to retrieve the data as strings, CStrings,longs (DWORD),doubles, and ints. The data is all stored as type char so it can be retrieved in any form it can be represented as. Notice above I get everything into a CString. This could just as easily be a double or int if the data could be described as that type of variable. Just pass GetField a reference to the type of data you wish returned and it does the conversion for you. Set Doc.rtf for details on these functions.

Comments
Unicode Support?
Posted by Legacy on 08/29/2000 12:00amOriginally posted by: Prasad
ReplyGood, but lacks support for embedded delimiters
Posted by Legacy on 05/28/2000 12:00amOriginally posted by: Roger C
This class could be made much more robust by adding support for string delimiters (sometimes called string identifiers)
that show where a string begins and ends. Such support should allow escaping the string delimiter by doubling the character. This means that a string could end with three consecutive string delimiters.
Thanks sharing code,
ReplyRoger
AfxExtractString
Posted by Legacy on 06/12/1999 12:00amOriginally posted by: Earl
Reply2 Errors when compiling in VC++ 6.0
Posted by Legacy on 04/15/1999 12:00amOriginally posted by: Joe Farkas
Reply