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 1.0k 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 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.

    JonBJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #7

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

      JonBJ E 2 Replies Last reply
      2
      • E emp1953

        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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on 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
        0
        • JonBJ JonB

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

          JonBJ 1 Reply Last reply
          0
          • JonBJ JonB

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

            Christian EhrlicherC 1 Reply Last reply
            0
            • E emp1953

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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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

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

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #6
                This post is deleted!
                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mchinand
                  wrote on last edited by
                  #7

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

                  JonBJ E 2 Replies Last reply
                  2
                  • M mchinand

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

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 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

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

                      E Offline
                      E Offline
                      emp1953
                      wrote on 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

                      • Login

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