0

I am trying to parse data from a text file that is formatted in a predefined way, as follows:

"GROUP","SCPT" "DATA","CPT1","1","0.000","0.004","","-0.2","-0.5","","",""

I am using boost::tokenizer to do the parsing, as follows:

using Tokenizer = boost::tokenizer<boost::escaped_list_separator<char>>;
Tokenizer tokens{line}; // line is read from a file stream
for(auto data : tokens) { 
// ... code follows

However, that gives me the tokens "GROUP" and "SCPT" instead of GROUP and SCPT (i.e. it includes the quotes in the token).

I have tried using my own separator:

boost::escaped_list_separator<char> els('\\', ',\"', '\"');
Tokenizer tokens{line, els}; 

but this doesn't work.

Can anyone help me please to convert the data above into

GROUP/SCPT
DATA/CPT1/1/0.000/0.004//-0.2/-0.5///

(where the / delinetaes the tokens) instead of

"GROUP"/"SCPT"
"DATA"/"CPT1"/"1"/"0.000"/"0.004"/""/"-0.2"/"-0.5"/""/""/""

Thanks in advance for any help you can give.

Andrew

  • Parse out the token. Then further parse the token. – Eljay Mar 14 '20 at 12:39
  • Thanks for your answer. I know I can further process the tokens to remove the extraneous quotes but I assume that it is possible to do this in one step with an appropriate list separator. I just don't know what that separator is. – Andrew Bond Mar 14 '20 at 17:29

0 Answers0