The csv file I am trying to manipulate has a random number of records. The fields I am trying to change are always the 2nd and 4th fields. Basically what I am trying to do is enclose the data in the 2nd and 4th field with a double quote.
So for example, if my record is below
FieldOne,FieldTwo,FieldThree,FieldFour,FieldFive
I would want the output to be
FieldOne,"FieldTwo",FieldThree,"FieldFour",FieldFive
Thanks in advance
Modify Field In CSV File
Moderators: JRL, Dorian (MJT support)
Re: Modify Field In CSV File
Hi, this would be a simple way to do it. Hope it helps.
Code: Select all
//For illustration, data is read from label
LabelToVar>List,StrData,1,0,{"*/"}
//To read data from file use "ReadFile" instead and comment out / delete the "LabelToVar" above
//ReadFile>C:\...\datafile.csv,strData
Separate>strData,%CRLF%,strRecord
Let>resout=
Let>ct=0
While>ct<StrRecord_count
Add>ct,1
Let>tmp0=,
Separate>strRecord_%ct%,tmp0,strField
Let>strRecordNew=%strField_1%,"%strField_2%",%strField_3%,"%strField_4%",%strField_5%
Let>resout=%resout%%strRecordNew%%CRLF%
EndWhile
MDL>resout
//For file output this can be used instead of MDL
/*
IfFileExists>C:\...\ResFile.csv
DeleteFile>C:\...\ResFile.csv
Endif
WriteLn>C:\...\ResFile.csv,nWLNRes,resout
*/
/*
List:
FieldOne,FieldTwo,FieldThree,FieldFour,FieldFive
FieldOne,,FieldThree,FieldFour,FieldFive
FieldOne,FieldTwo,FieldThree,FieldFour,FieldFive
FieldOne,FieldTwo,FieldThree,FieldFour,FieldFive
FieldOne,FieldTwo,FieldThree,FieldFour,FieldFive
*/