Introduction
Basically, I've seen other string tokenizers and they lacked the functionality I was looking for. Therefore, I created one for myself using the KISS (Keep-It-Simple-Stupid) method. This is a VERY SIMPLE sample!!!!
Here is a summary of the functionality in the CTokenEx
class, you can:
- use
SplitPath
to break-up the path into sections (Drive/Share name, Directory, Filename, Extension). Also, recognizes UNC names (which _tsplitpath
doesn't).
- use
Join
to create a CString
from a CStringArray
with delimiters of your choice.
- use
Split
to break-up a CString
into a CStringArray
(according to the delimiter).
- use
GetString
to get the first sub-string in a CString
(according to the delimiter).
NOTE:
The Split
and GetString
functions recognize multiple delimiters as an empty string so that it will NOT add blanks to an array (unless you want it to). See example code below:
Say you have a CString
that contains: "abc,def,,,ghi,,jkl,,"
void <SOME NAME>Dlg::OnSplit()
{
CTokenEx tok;
CString csSplit = "abc,def,,,ghi,,jkl,,";
CStringArray SplitIt;
tok.Split(csSplit, ",", SplitIt, TRUE);
tok.Split(csSplit, ",", SplitIt, FALSE);
}
I hope that others find this class useful.