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?

    Indika.


  • Qt Champions 2017

    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(",");


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.