creating tokens from csv

18 views Asked by At

I have a program which reads csv file and split it on token comma.

But i am having a problem in one case

for ex here is demo csv file content:-

val1,val2,val3,val4

1,"test,test1",,0

In this case i am getting "test as one token and test1" as another token.

Please any one help me to resolve this problem.

Here is code i am using for splitting.

std::vector<std::string> split(std::string strToSplit, char delimeter)

{

    std::stringstream ss(strToSplit);
    std::string item;
    std::vector<std::string> splittedStrings;
    while (std::getline(ss, item, delimeter))
    {
        splittedStrings.push_back(item);
    }
    return splittedStrings;
}


bool ReadCsv( UnicodeString usCsvFilePath )

{

    bool bRetVal = false;
    std::vector<std::string> splittedStrings
    TStringList* pStrList = new TStringList;
    if( pStrList )
    {
        pStrList->LoadFromFile( usCsvFilePath );
        for(int i = 0; i < pStrList->Count ; i++ )
        {
            str = pStrList->operator [](i);
            splittedStrings = split(str, ',');
            bRetVal = DoSomeWork(splittedStrings);

        }

    }
    delete pStrList;
    return bRetVal;
}
0

There are 0 answers