Delphi读取下一行并替换
我有一个程序导入一个包含许多条目的文本文件:
###
Starttime: 06.03.2008
Data: SOME RECORDS HERE
###
Starttime: 21.03.2008
Data SOME RECORDS HERE
... 等等
不是我想在“数据:”之后有一个结束时间,这是下一个开始时间-1,所以我有
###
Starttime: 06.03.2008
Data: SOME RECORDS HERE
EndTime: 20.03.2008
###
Starttime: 21.03.2008
Data SOME RECORDS HERE
EndTime: (next starttime -1)
...... 等等
I have a program that imports a text file that has many entrys:
###
Starttime: 06.03.2008
Data: SOME RECORDS HERE
###
Starttime: 21.03.2008
Data SOME RECORDS HERE
...
and so on
Not I want to have an end time after "Data:" that is the next starttime -1 so i have
###
Starttime: 06.03.2008
Data: SOME RECORDS HERE
EndTime: 20.03.2008
###
Starttime: 21.03.2008
Data SOME RECORDS HERE
EndTime: (next starttime -1)
...
and so on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是将文件读入 TStringList 并在那里工作。
伪代码:
此代码不是很健壮,它不会检查任何特殊情况,例如第一个开始日期,但它应该足以让您开始。
The easiest way would be to read the file into a
TStringList
and work there.Pseudocode:
This code is not very robust, it doesn't check for any special cases, like the first starting date, but it should be enough to get you started.
那么,您必须逐行复制文件,并在适当的时候插入新行。 您无法移动文本文件中的内容。
Well, you will have to Copy the file, line by line, and insert the new lines at the right moment. You can't shift stuff in a text file.