You can (of course) easily create an array of CQStringParser objects if needed, and read in an entire delimited file before processing the parsed strings. Alternatively, you can use the same object over and over again with different strings.

The parsed fields begin at element #1 because I store the original string in element 0.

How To Use CQStdStringParser

Add the following include:

#include"QStdStringParser.h"

And where it's needed, do something like this (I used this code to test the class):

The strings being passed into the class and retrieved from the class are of type std:string, but other than that, the class functions identically to its MFC-specific cousin (which works with CStrings).

Updates

06 May 2001 - As I use my classes they mature and grow, and CQStringParser is no exception. In this iteration, I've simplified the code by eliminating the overloaded constructor and parsing functions. I've also added new functionality. You can now Add, Set (change), Insert, and Delete fields from the parsed string. The demo (link at top this article) includes a simple dialog-based application which allows you to play around with the primary functionality of the class. As usual, the class is fully documented. Have a ball.

10 August 2001 - I recently had reason to need the use of this class in a NON-MFC evnironment, and in order to facilitate this requirement, I created a new version of the class that uses STL instead of the MFC collection classes. The demo program now contains both the CQStringParser class, as well as the CQStdStringParser class. The only externally obvious difference is that the strings you pass in and get back are of type std::string instead of CString. The method names and class functionality are otherwise identical to the original class.

15 March 2002 - Fixed a parsing bug in the string parser classes, and changed the sample app to allow you to change the quote and/or delimiter character in the dialog box.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Share

About the Author

I've been paid as a programmer since 1982 with experience in Pascal, and C++ (both self-taught), and began writing Windows programs in 1991 using Visual C++ and MFC. In the 2nd half of 2007, I started writing C# Windows Forms and ASP.Net applications, and have since done WPF, Silverlight, WCF, web services, and Windows services.

My weakest point is that my moments of clarity are too brief to hold a meaningful conversation that requires more than 30 seconds to complete. Thankfully, grunts of agreement are all that is required to conduct most discussions without committing to any particular belief system.

</small>
I don't think so. AddField adds a new element to the list, and then rebuilds the original string from the new list. Yours is just a different (and less efficient) way to do it. I don't see any problems in the existing code.

<small>L. Kohnert wrote:
</small>

Again, not a "bug", just a different way to do it.

For the record, I see no real benefit in using STL. I write Windows apps using VC++, and have no desire, inclination, requirement, nor interest in porting them to another platform. I provided the STL version for those people who absolutely refuse to use MFC. I learned exactly enough about STL to convert the class to use the [STL] library. However, I thank you for pointing out an eaiser way to replace a given list element with new data.

------- signature starts

"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

The app I'm writing at work right now where I'm pulling data from Lotus Notes through COM. The Notes application I'm tying into contains a few environment variables that some idiot Notes developer thought would be neato to delimit with his own tag system (eg. <XX>). I've run into this a lot - where the delimiter is something like "XXXXX".

"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997-----"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

I like this class very much. It saved me the time to make a parser myself. I came to know of this class, when you posted a long time ago about users rating articles low due to factors other than technical merit. When I needed a string parser, I thought - John has posted one at CP, let me check that out first. I just rated this - Excellent.