在c#中编辑优秀文件 [英] Editing great files in c#

查看:90
本文介绍了在c#中编辑优秀文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

目前我正在处理一个小应用程序,该应用程序将处理greate Textfiles。

如何阅读和解释内容实际上没有问题,但我也想保存文件非常有效(没有工作时间超过10~15秒)。最好的文件大约500Mb。



我基本上想要做的是编辑文件中的几行。



关于

Hello
currently I am working on a small application which shall handle greate Textfiles.
How to read and interprete the content is actually no Problem but I also want to save the file very efficient (No working times over 10~15sec). The greatest file is about 500Mb big.

What I basically want to do is to edit several line in the file.

regards

推荐答案

确实没有太多选择:你可以每次编写整个修改过的文件,或者你可以从点开始编写文件从第一个修改开始。



问题是文本文件不理解行 - 内容只是一系列字符 - 所以如果你插入或删除单个字符必须移动从文件的点到末尾的每个字符。没有在此插入文本或删除此文本的功能,因为文件没有结构或组织。



因此,如果您的文件写入10秒,然后需要10秒 - 这是将数据写入硬盘所需的时间。



你唯一能做的就是构建你dtaa,以便您可以插入和删除部分(不太可能)或将写入代码移动到后台任务中,以便在用户不会注意到它仍在继续的情况下继续执行。
There really isn't much option: you can write the whole revised file each time, or you can write the file from the point of the first modification onwards.

The problem is that text files don't understand lines - the content is just a sequence of characters to them - so if you insert or delete a single character every single character from the point to the end of the file has to be moved. There is no function for "insert text here" or "delete this text" because there is no structure or organisation to the file.

So if your file write is taking 10 seconds, then it will take 10 seconds - that's how long it takes to get the data written to the HDD.

The only thing you can do is either structure you dtaa so that you can insert and deleted portions (unlikely) or move the write code into a background task so that it proceeds without the user noticing it is still going on.


加快速度,我相信你必须加载内存(并精心制作)文件的大块(或整个文件,如果可以的话)。
To speed up things, I believe you have to load in memory (and elaborate) large chunks of the file (or the whole file, if you can).


到目前为止。

关于我的申请的一些事实:

文件xy.txt看起来像:

Thanks so far.
Some Facts about my application:
The file xy.txt look like:
Bla blabla blablabla



我基本上使用Split函数来读取txt


I basically use the Split function to read through the txt

string txt = "Bla blabla blablabla"; //Just a example actually I am reading a extern file
string[] word = text.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries);



现在我通过数组搜索某些文本,如 blabla 如果该行包含此文本我想删除它
到目前为止,
非常好。

我的想法是在列表中填写所有不包含此文本的行,并在Streamreader完成后,我想用列表的内容重写该文件。



你怎么看?


Now I go through the Array an search for certain text like blabla if the line contains this text I want to delete it
so far so good.
My idea is to fill all lines which not contain this text in a list and after the Streamreader is finished I want to rewrite the file with the Content of the list.

What do you think of it ?


这篇关于在c#中编辑优秀文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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