查找和从vb.net替换文本文件 [英] Find & replace in Text file from vb.net

查看:94
本文介绍了查找和从vb.net替换文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在桌面应用程序(vb.net)中处理文本文件.框架是3.0.
我有几个(例如10个)文本文件,每个文件包含10,000条记录.
例如
17725534 874893829834
17725535 313554132154
17725536 981521451554
等等.

我还有另一个文件,其中包含10个文件中的200条记录,称为Missing.txt.
例如
17725534 874893829834第1个文件的第1行.
27725537 564355432154第2个文件的第3行.
57725564 156548545484第5个文件的第30行.
直到200条记录.

现在我要检查10个文件以获得200条记录.
意思是,我将从Missing.txt中获取第一条记录,并在10个文本文件中循环查找相同的内容.

如果我在10个文件中找到任何记录,它将被删除或替换为零(0)(在同一文件中,不在Missing.txt中).
我无法删除记录或替换记录.
是否有ant IO功能来替换特定行或将其删除..?

Thanx ..

hi to all,

I am working with text files in desktop app(vb.net). Framework is 3.0.
I have a several(e.g. 10) text files each containing 10,000 records.
e.g.
17725534 874893829834
17725535 313554132154
17725536 981521451554
and so on.

I have another file containing 200 records called Missing.txt, from within 10 files.
e.g.
17725534 874893829834 1 st row from 1st file.
27725537 564355432154 3 rd row from 2st file.
57725564 156548545484 30 th row from 5st file.
so on till 200 records.

Now I want to check 10 files for 200 records.
Means, I will take 1 st record from Missing.txt & loop in 10 text files to find the same.

If I found any records in 10 files, either it''ll deleted or replaced with zeros(0)(In same file, not in Missing.txt).
I am not able to delete the record or replace the same.
Is there ant IO function to replace particular line or to delete it..?

Thanx..

推荐答案

您的描述非常混乱.我们不知道您真正遇到什么问题,因此,一般性解释为:

您必须逐行阅读文件以查找所需内容.如果找不到,请将行写到新文件中.

如果确实找到了要查找的内容,请对行进行适当的处​​理,然后将其写入新文件.

重复执行直到源文件的末尾,然后关闭文件并对它们进行任何操作.


...顺便说一句:它们被称为文本文件"而不是记事本文件".
Your description is pretty confusing. We have no idea what you''re really having a problem with, so, the generic explanation:

You have to read the file line by line to find what you''re looking for. If you don''t find it, write the line out to a new file.

If you do find what you''re looking for, manipulate the line however appropriate, then write it to the new file.

Repeat until the end of the source file, then close the files and do whatever you wish with them.


...BTW: They''re called "Text Files" not "Notepad Files".


Harshad,
请参考此链接以实现您的目标-
searching-for-line-of-一个文本文件在另一个文本文件中 [ [链接] [ [链接] [ [链接] [ ^ ]
4.比较二维数组中的适当列,并检查其中是否包含另一个 [链接] [^ ]
5.将内容写回到第3个文件 [链接] [ ^ ]
Hi Harshad,
Refer this link to achieve your goal-
searching-for-line-of-one-text-file-in-another-text-file[^]

Or follow these steps-
1. read both files line by line [Link][^]
2. split each line on their white spaces [Link][^]
3. for both files, create a 2 dimensional array [Link][^]
4. compare the appropriate columns from your 2 dimensional arrays to each other and check if one contains the other [Link][^]
5. write something back to a 3rd file [Link][^]


这篇关于查找和从vb.net替换文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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