Delphi程序上复制了一个csv列
问题描述:
我正在使用Delphi,我需要以编程方式复制一个列,它是.csv文件中的数据。
I am using Delphi and I need to programmatically duplicate a column and it's data from a .csv file.
我需要做的这个确切的任务是: / p>
The exact task I need to do it this:
1. Load the csv content (could be into a stringlist or other)
2. Copy column 4 (and it's data)
3. Add a new column on column 2's place and add this copied column
4. Save
这是Delphi能做的事吗?如果有的话,任何人都可以启动或指导如何做到这一点?
Is this something Delphi can do? If so, can anyone get me started or guide on how to do this?
答
Create two stringlists `Data` and `Temp`
Load file into Data
For every line of Data:
Assign this line to Temp.CommaText
(this assumes that line format doesn't violate CommaText rules,
otherwise do partition by hands or with dedicated CSV libraries)
Insert Temp[3] before Temp[1]
Assign CommaText back to Data line
Save Data
Free objects