Click here to Skip to main content
15,940,246 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I want to read comma separeted file. I am able to read comma separeded file with string tokenizer but if there are spaces between string line it throw exception.

example: 1,2,asd,sdf,e,f,j,t,7

I can save it and open it (from listcontrol to .csv file and vice-versa). But if string is = 1,2, ,sdf,e,f, , ,7

If there are spaces between stringline, I can save it into .csv file but can not open it into listcontrol.
C++
if( File.Open(fileDlg.GetFileName(), CFile::modeRead)) 
{
	while(File.ReadString(strLine)) // Read file line by line
{
   int total = (int)m_Events.GetItemCount();
   while(strLine.Tokenize(Seperator, Position)!="")
{
	
	// Token seperators.
    for ( int ii=0; ii<total;>    {
	int Position = 0;
      	Token = strLine.Tokenize(Seperator, Position);

    for(int j=0; j<=17;j++)
    {
	  m_Events.SetItemText(ii,j,Token);
      	  Token = strLine.Tokenize(Seperator, Position);
    }
     File.ReadString(strLine);

    }
}

}
}

Thank you.
Posted
Updated 16-May-13 4:12am
v2
Comments
Sergey Alexandrovich Kryukov 16-May-13 10:14am    
Maybe this is because a compiler get offended with the spelling: "Seperator" :-).
—SA
Richard MacCutchan 16-May-13 12:08pm    
You are making a number of calls to Tokenize without checking the return value to see whather you have reached the end of the string.

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



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