A Simple CString Tokenizer | CodeGuru

A Simple CString Tokenizer

As the name suggests, this is a simple class to extract tokens from a CSting. I wrote this class becuase during the course of my final year project at University I needed a simple way to extract ‘tokens’ from a CString. This is what I came up with. Its probably not the best or most […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 3, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

As the name suggests, this is a simple class to extract tokens from a CSting. I wrote
this class becuase during the course of my final year project at University I needed a
simple way to extract ‘tokens’ from a CString. This is what I came up with.
Its probably not the best or most effeicent way to accomplish the task – but it works
which in the main thing.

To use the CToken class:

-First include the CToken header file in your porgram:

#include “Token.h”

-Then you are free to create and use an instance of CToken. For example:

CString str = "A B C D"
CString newTok;
CToken tok(str);
tok.SetToken(" ");
while(tok.MoreTokens())
{
   newTok = tok.GetToken()
}

Improvements:
If people can suggest any improvements or there bugs please drop me an email

Download demo project – 15 KB

Download source – 3 KB

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.