Delphi程序上复制了一个csv列 [英] Delphi programatically duplicating a csv column

查看:585
本文介绍了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

这篇关于Delphi程序上复制了一个csv列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆