Click here to Skip to main content
15,304,157 members
Articles / Programming Languages / C++
Posted 13 Apr 2001


31 bookmarked

Yet another string parser

Rate me:
Please Sign up or sign in to vote.
3.44/5 (9 votes)
15 Mar 2002Public Domain
Another class for extracting fields of string

Sample screenshot


This is just another string parser that can be used either for command line or for CSV file for instance. This implementation uses the minimum amount of memory and time to parse a string into tokens.

Sample code

CStringParser args;
args.Parse( ::GetCommandLine(), poCmdLine ); 
args.Parse( _T("\"BOS011\" \"2001/04/09 08:49:09:0"
  "\" \"Hooker\" \"\" \"Boston\" \"No SMS "
  "client detected\" \"No\" \"No\""), poCsvLine ); 
args.Parse( _T("BOS011,\"GHA\",\"\",\"\","
  "Microsoft Windows NT Advanced Server 4.0,BOSTON,BOSTON,"
  "SSMS1,2.00.1493.2009,5,1"), CParseOptions( ',', '"', '\0', FALSE ) );


There are 2 projects to try this class - One is a simple console, the other is a complete GUI dialog box application to check each possibility of the class (using MFC). Have a nice trip with it.

Sorry for the lack of proper documentation but still have no time for it. Just read the code -both classes are not too hard.


By the way, I did some changes in the parser :

  • Can keep the quotes in the parsed argument by SetKeepQuote(true).
  • Can get the trailing null argument by SetRTrim(false).


This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

France France
No Biography provided

Comments and Discussions

QuestionLicense information for this article Pin
Ori Saporta29-Apr-15 1:01
MemberOri Saporta29-Apr-15 1:01 
AnswerRe: License information for this article Pin
Remon24-May-15 9:49
MemberRemon24-May-15 9:49 
GeneralIt has a bug [modified] Pin
Ali Rafiee15-Jul-08 11:06
MemberAli Rafiee15-Jul-08 11:06 
GeneralGood job Pin
N5ARW19-Jan-07 12:16
MemberN5ARW19-Jan-07 12:16 
GeneralANSI string version also available Pin
Bill Kudrle25-Jul-03 13:04
MemberBill Kudrle25-Jul-03 13:04 
GeneralDouble Quote Bug Fix Pin
_dew_20-Jul-03 21:38
Member_dew_20-Jul-03 21:38 
GeneralVery good, exellect, (except one point) Pin
sequaier25-Nov-02 15:58
Membersequaier25-Nov-02 15:58 
GeneralRe: Very good, exellect, (except one point) Pin
Remon26-Nov-02 8:00
MemberRemon26-Nov-02 8:00 
GeneralRe: Checked it.. ^^ Pin
sequaier27-Nov-02 13:00
Membersequaier27-Nov-02 13:00 
GeneralNice code!!! Pin
7-Mar-02 4:37
suss7-Mar-02 4:37 
GeneralI like it Pin
12-May-01 11:16
suss12-May-01 11:16 
QuestionDocs? Pin
25-Apr-01 11:33
suss25-Apr-01 11:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.