Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
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 :
C++
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);
                m_List2.SetItemText(ii,j,Token);
            }
            
        } 
        	
    }
            
    //AfxMessageBox(strMsg, MB_ICONINFORMATION); 
    // Display resulting contents of strMsg in a message box 
    
}

}
Posted
Updated 7-Feb-13 5:43am
v2
Comments
Chris Reynolds (UK) 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.
Sergey Alexandrovich Kryukov 7-Feb-13 12:01pm    
MFC..?! Why not using the standard things? std::string and everything else of std?
—SA
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.
Sergey Alexandrovich Kryukov 7-Feb-13 13:41pm    
Maybe, but it's still a proprietary thing. Why creating a vendor lock-in?
—SA

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).
 
Share this answer
 
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: http://www.oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html[^].

—SA
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900