Remove comma separator from lines read in from a .csv file
-
wrote on 28 Jan 2022, 15:51 last edited by
I am reading lines from a .csv into a QStringList. Then use a stringlist.split("/n") to put the individual lines into the elements of the stringlist. I settext each stringlist item into a QTextEdit box. The comma is displayed each time. How do I discard this comma so that it is not displayed. I append text where the comma should NOT be.
-
wrote on 28 Jan 2022, 16:13 last edited by
You could split on ",\n" and instead of just "\n".
-
I am reading lines from a .csv into a QStringList. Then use a stringlist.split("/n") to put the individual lines into the elements of the stringlist. I settext each stringlist item into a QTextEdit box. The comma is displayed each time. How do I discard this comma so that it is not displayed. I append text where the comma should NOT be.
wrote on 28 Jan 2022, 16:01 last edited by@emp1953
How many commas/fields per line? Just one? Normally you might split each line on","
to get a list of its fields, there may be many commas/fields. Otherwise what do you want to do --- simply remove the last character of each line? -
@emp1953
How many commas/fields per line? Just one? Normally you might split each line on","
to get a list of its fields, there may be many commas/fields. Otherwise what do you want to do --- simply remove the last character of each line? -
@emp1953
How many commas/fields per line? Just one? Normally you might split each line on","
to get a list of its fields, there may be many commas/fields. Otherwise what do you want to do --- simply remove the last character of each line?wrote on 28 Jan 2022, 16:09 last edited by@JonB I tried a split on the comma " , " rather than the "\n" and the QTextEdit box ended up going to a scrolled affair with one line in it still with the comma at the end which is not the desired effect. The screen has 40 QTextEdit boxes where this data is to be readily readable. The user should not have to scroll each box to read it.
-
@JonB There is one field per line like below:
Air handler 1 In,
Air handler 1 Out,
Air handler 2 In,
Air handler 2 Out,Etc......
wrote on 28 Jan 2022, 16:10 last edited by@emp1953
QString &QString::remove(int position, int n) could be used to remove the last character from aQString
, or void QString::chop(int n) does just that. Lots of available methods inQString
. -
@JonB I tried a split on the comma " , " rather than the "\n" and the QTextEdit box ended up going to a scrolled affair with one line in it still with the comma at the end which is not the desired effect. The screen has 40 QTextEdit boxes where this data is to be readily readable. The user should not have to scroll each box to read it.
This post is deleted! -
wrote on 28 Jan 2022, 16:13 last edited by
You could split on ",\n" and instead of just "\n".
-
wrote on 28 Jan 2022, 16:24 last edited by
@mchinand This solved my problem. I'm refactoring code that uses data files that were previously generated into Excel Spreadsheets. The user stopped paying for the MSOffice subscription to keep Excel running so now the DAQ equipment is outputting a .csv
I did a hex dump on a couple of files and it appears that the DAQ equipment automatically puts a comma at the end of the line. It's not new equipment so perhaps when it was designed there was some requirement for a .csv line to end with a comma.
1/9