Click here to Skip to main content
12,946,164 members (53,176 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Please help me with string tokanize. my input file is text file such as

1,xyz,1 HP-1 Sigma,1.0,Y,Single,,
2,dfg,32 KES LW0090 ,1.0,Y,Single,,

with this code I am getting assertion iStart>=0 and only one string.(except 1)
xyz,1 HP-1 Sigma,1.0,Y,Single

this string

my code :
if(File.Open(pathName, CFile::modeRead)) // Open file to be read 
    while(File.ReadString(strLine)) // Read file 
        int Position = 0;
        CString Token;
        Token = strLine.Tokenize(",", Position);
        while(Token!=" ")
         int total = (int)m_List2.GetItemCount();
         for ( int ii=0; ii< total; ii++ )//for row
            for(int j=0; j<=6;j++) //for columns
                CString Token=strLine.Tokenize(",",Position);
    //AfxMessageBox(strMsg, MB_ICONINFORMATION); 
    // Display resulting contents of strMsg in a message box 
Posted 7-Feb-13 4:25am
Updated 7-Feb-13 5:43am
Chris Reynolds (BNY) 7-Feb-13 11:32am
I'm not quite sure what you're trying to do as you're looping through each line in the file, then looping through rows in a list so you're processing the line too often as you'll have exhausted the line by the time you've completed the first iteration round the ii loop. Other than that I'd check for Position != -1 rather than Token !=" " in your while loop
peoria123 7-Feb-13 11:44am
I want to open text file into Listcontrol. listcontrol has 6 columns,
1,xyz,1 HP-1 Sigma,1.0,Y,Single,,
(comma separeted columns)
Thank you.
MFC..?! Why not using the standard things? std::string and everything else of std?
H.Brydon 7-Feb-13 13:05pm
Nothing wrong with CString. It also has tokenizing features that std::string doesn't have.

I would do it with CString.
Maybe, but it's still a proprietary thing. Why creating a vendor lock-in?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I disagree that CString/MFC is a bad idea (but agree that it may be considered "proprietary" Microsoft).

The CString class has a tokenizer built into it, described here[^]. Never mind the "CStringT" stuff ... it applies to CString.

Joseph Newcomer has written an excellent article about CString which can be found here[^], with the CP version here[^] (no special info on tokenizing in these articles).
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Please see my comment to the question. Using proprietary and outdated MFC is a really bad idea, especially for such universal chores.
You will get a better idea, for example, from here:[^].


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,205
Maciej Los 2,453
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100