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. CSV file handling with modification
Qt 6.11 is out! See what's new in the release blog

CSV file handling with modification

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 598 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.
  • I Offline
    I Offline
    indikaur
    wrote on last edited by indikaur
    #1

    Hi,

    I need to process a CSV file and do some formatting on certain columns such as padding characters and replace some text within the column. So I think below are the specific tasks to achieve. Line ending should not be altered.

    • Read header and identify the colums positions to be modified.
    • Read a line and do the modification in the identified column positions.

    I already have obtained the column positions correctly from header. How can I modify columns while reading a single line?

    Indika.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome
      Maybe something like
      QString line= file.readline();
      QStringList Fields=line.split(",");
      now
      each field is in the list
      Fields[0], Fields[1]
      so Fields[4]="changed";
      then put them back.
      line=Fields.join(",");

      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