编辑现有平面文件中间部分的最佳方法是什么? [英] What is the best way to edit the middle of an existing flat file?

查看:91
本文介绍了编辑现有平面文件中间部分的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工具,可以为仿真创建变量.当前的工作流程涉及将这些变量手动复制到模拟输入文件中.输入文件是标准的平面文件,即不是二进制或XML.我想自动将变量添加到平面输入文件中.

I have tool that creates variables for a simulation. The current workflow involves hand copying those variables into the simulation input file. The input file is a standard flat file, i.e. not binary or XML. I would like to automate the addition of the variables to the flat input file.

变量将复制文件中现有的变量,例如

The variables copy over existing variables in the file, e.g.

新变量: 长度10 身高20 深度30

New Variables: Length 10 Height 20 Depth 30

旧变量: ... 体重100 20岁 长度10 身高20 深度30 ...

Old Variables: ... Weight 100 Age 20 Length 10 Height 20 Depth 30 ...

希望将旧变量复制到新变量上.它们在平面输入文件中为200行.

Would like to have the old variables copy over the new variable. They are 200 lines into the flat input file.

感谢您的见解.

P.S.这是在Windows上.

P.S. This is on Windows.

推荐答案

如果您坚持使用平面,那么您将采用老式的更新方式:从原始文件读取,写入临时文件,或者写入原始行或更改数据,然后将其写入.要添加数据,请在适当的时候将其写入临时文件.要删除数据,只需不要从原始文件中复制即可.

If you're stuck using flat, then you're stuck using the old fashioned way of updating them: read from original, write to temp file, either write the original row or change the data and then write that. To add data, write it to the temp file at the appropriate point; to delete data, simply don't copy it from the original file.

最后,关闭两个文件并将临时文件重命名为原始文件名.

Finally, close both files and rename the temp file to the original file name.

或者,可能是时候考虑一​​个小的数据库了.

Alternatively, it might be time to think about a little database.

这篇关于编辑现有平面文件中间部分的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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