Regarding reading CSV file
Hi All
I have written a code to read the *.csv file and is working fine.Below is my code
- {
- QStringList listdata;
- listdata = line.split(',');
- int iHeaderCount = listdata.count();
- *HeaderCnt = iHeaderCount;
- while (!line.isNull())
- {
- line = in.readLine();
- line.remove(" ");
- listdata.append(line.split(','));
- }
- }
But when my data in *.csv file is as below
“1”,“2”,“3”,“4”,“11,22,33”,“4”,“5”,“6”,“7”
I want to read 11,22,33 as one value.How to do that?
6 replies
If you’ve got control over CSV file itself, the easiest way would be, of course, to use another delimiter (like ‘;’), then reading would be pretty straightforward.
Here, if you want to check for those 11,22,33 sequences AFTER splitting, you can check the resulting strings for ‘”’ character. A lack of at leas one would indicate, that you are inside the sequence. This does not seem to be a very elegant way, though.
If you want to check BEFORE splitting, you might want to consider using ‘”’ as the delimiter – this way you would get loads of rubbish results (’,’), but they can be easily filtered out.
Or, as probably the easiest route, you can simply use “,” (quote, comma, quote) as your delimiter.
See this thread [developer.qt.nokia.com] and this thread [developer.qt.nokia.com] for further reference and possible solutions.
You should avoid writing your own CSV parser if it is by any means possible for you to use an existing solution!
See this thread [developer.qt.nokia.com] and this thread [developer.qt.nokia.com] for further reference and possible solutions.You should avoid writing your own CSV parser if it is by any means possible for you to use an existing solution!
Rajveer, judging from Volker’s links, you’ve already asked about CSV parsing twice, and been given elaborate and instructive responses every time. Try being a bit more considerate about other peoples’ time in the future, please.
Maybe this will help: http://libqxt.bitbucket.org/doc/tip/qxtcsvmodel.html
You must log in to post a reply. Not a member yet? Register here!




