1754312 Members
2649 Online
108813 Solutions
New Discussion

Parsing Line

 
Tnameh
Occasional Advisor

Parsing Line

I am using CSV file, and I need to parse in C++, I have some data I know how many columns I have.
########################
“user1”,”user2”,”user3”, “user4”,”user5”,
“use””r1”, “user,2”, “use,r3”,”user,rr,
Rr,rree4”,”user5”,
##########################

First line I am able to parse. But for second row I am facing issue if data is incomplete in 1st line I have to pick next line, until I find all the columns. Column separator is (,”). Please give compile code so that I can test. Reward assured for good answer.

How can I parse data of 2nd row, I am using STL, but I don’t know how to
find last of (,”) and (,” ) first of in next line.

It should return me for 2nd row.
“use””r1”
“user,2”
“use,r3”
”user,rr,Rr,rree4”
“user5”
1 REPLY 1
Dennis Handly
Acclaimed Contributor

Re: Parsing Line

>Column separator is (,").

It seems you need a character orientated state machine that knows how to parse your CSV lines.
This would include removing "", collapsing the duplicated "". (It appears you don't care to do this, just recognize them and know when a comma is a separator.)

And most importantly knowing when to ignore the newline that's embedded in a quoted string.
This could be as simple as checking if the last two chars of a string are a: ",
If not, read another line and concatenate the two.