Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Remove comma separator from lines read in from a .csv file
Forum Updated to NodeBB v4.3 + New Features

Remove comma separator from lines read in from a .csv file

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 983 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    emp1953
    wrote on 28 Jan 2022, 15:51 last edited by
    #1

    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.

    J 1 Reply Last reply 28 Jan 2022, 16:01
    0
    • M Offline
      M Offline
      mchinand
      wrote on 28 Jan 2022, 16:13 last edited by
      #7

      You could split on ",\n" and instead of just "\n".

      J E 2 Replies Last reply 28 Jan 2022, 16:16
      2
      • E emp1953
        28 Jan 2022, 15:51

        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.

        J Offline
        J Offline
        JonB
        wrote on 28 Jan 2022, 16:01 last edited by
        #2

        @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?

        E 2 Replies Last reply 28 Jan 2022, 16:06
        0
        • J JonB
          28 Jan 2022, 16:01

          @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?

          E Offline
          E Offline
          emp1953
          wrote on 28 Jan 2022, 16:06 last edited by
          #3

          @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......

          J 1 Reply Last reply 28 Jan 2022, 16:10
          0
          • J JonB
            28 Jan 2022, 16:01

            @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?

            E Offline
            E Offline
            emp1953
            wrote on 28 Jan 2022, 16:09 last edited by
            #4

            @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.

            C 1 Reply Last reply 28 Jan 2022, 16:11
            0
            • E emp1953
              28 Jan 2022, 16:06

              @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......

              J Offline
              J Offline
              JonB
              wrote on 28 Jan 2022, 16:10 last edited by
              #5

              @emp1953
              QString &QString::remove(int position, int n) could be used to remove the last character from a QString, or void QString::chop(int n) does just that. Lots of available methods in QString.

              1 Reply Last reply
              0
              • E emp1953
                28 Jan 2022, 16:09

                @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.

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 28 Jan 2022, 16:11 last edited by
                #6
                This post is deleted!
                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mchinand
                  wrote on 28 Jan 2022, 16:13 last edited by
                  #7

                  You could split on ",\n" and instead of just "\n".

                  J E 2 Replies Last reply 28 Jan 2022, 16:16
                  2
                  • M mchinand
                    28 Jan 2022, 16:13

                    You could split on ",\n" and instead of just "\n".

                    J Offline
                    J Offline
                    JonB
                    wrote on 28 Jan 2022, 16:16 last edited by JonB
                    #8

                    @mchinand
                    ...till we find out that not every line does end in a comma... :) I didn't think CSV files put in trailing comma on each line, wonder if it's actually two fields and the second one is empty....

                    1 Reply Last reply
                    1
                    • M mchinand
                      28 Jan 2022, 16:13

                      You could split on ",\n" and instead of just "\n".

                      E Offline
                      E Offline
                      emp1953
                      wrote on 28 Jan 2022, 16:24 last edited by
                      #9

                      @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 Reply Last reply
                      1

                      1/9

                      28 Jan 2022, 15:51

                      • Login

                      • Login or register to search.
                      1 out of 9
                      • First post
                        1/9
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved