Important: Please read the Qt Code of Conduct -

CSV file handling with modification

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


  • Lifetime Qt Champion

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

Log in to reply