Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
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);
                m_List2.SetItemText(ii,j,Token);
            }
            
        } 
        	
    }
            
    //AfxMessageBox(strMsg, MB_ICONINFORMATION); 
    // Display resulting contents of strMsg in a message box 
    
}
 
}
Posted 7-Feb-13 5:25am
Edited 7-Feb-13 6:43am
v2
Comments
Chris Reynolds (BNY) at 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 at 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 at 7-Feb-13 12:01pm
   
MFC..?! Why not using the standard things? std::string and everything else of std?
—SA
H.Brydon at 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 at 7-Feb-13 13:41pm
   
Maybe, but it's still a proprietary thing. Why creating a vendor lock-in?
—SA
Rate this: bad
good
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).
  Permalink  
Rate this: bad
good
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: http://www.oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html[^].
 
—SA
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2014
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