vb .net从文本文件中提取数据 [英] vb .net extract data from a text file

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

问题描述



我需要有关从特定文本文件中提取数据的帮助,并且需要从该文件中提取其中的数据,我需要从该文件中生成3个文本文件.
有人可以帮忙吗?

特定文件(txt文件)

使用VB .net运行应用程序

收集数据

产生3个文本文件


任何帮助将不胜感激.
感谢

Hi,

I need help on extracting data from a specific text file and in which data from that file i would need to produce 3 text files from that file.
can someone help on how to do this?

SPECIFIC FILE(txt file)
to
run application using VB .net
to
gather data
to
produce 3 text files


any help would be appreciated.
thanks

推荐答案

1-读取文件.

2-将要写入的数据提取到一个文件中(可以使用正则表达式),然后将该数据写入一个单独的文件中.


您可以在Google中获取大量示例,以使用C#读写文件.尝试一下,如果您在执行此操作时遇到任何问题,请提出问题.
1- Read the file.

2- Extract the data which you want to write in a single file (you can use regular expression for that) and write that data to a separate file.


You can get lot of samples in google to read and write a file using C#. Try this and if you face any issue in implementing this then ask the question.


总之:

1)声明一个流读取器以读取您的文件
In short:

1) Declare a streamreader to read your file
Dim tRead As System.IO.StreamReader



2)打开文件



2) Open your file

tRead = IO.File.OpenText(filename)



3)逐行读取文件(一次或一次)



3) Read your file (at once or) line by line

readstring = tRead.ReadLine()



4)提取需要提取的(多个)字符串中的任何内容.



4) Extract whatever you need to extract in (multiple) strings.

writestring = "...."



5)编写新文件



5) Write your new file(s)

IO.File.WriteAllText(filename2, writestring, System.Text.Encoding.Default)



6)关闭文件



6) Close your file

tRead.Close()


下面要说的是您的txt文件的内容格式,以制表符分隔

价格供应商产品
1 B面包
2 c香皂

您可以按照\ r \ n的选项卡将其拆分,并从array获取第二个索引

看起来像这样

[0] 1
[1] B
[2]面包
let say below is the content format of your txt file in tab separated

Price Supplier products
1 B Bread
2 c Soap

you may just split it by tab per \r\n and get the 2nd index from array

it will look like this

[0]1
[1]B
[2]Bread


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

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