Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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.
 
Share this answer
 
In short:

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


2) Open your file
tRead = IO.File.OpenText(filename)


3) Read your file (at once or) line by line
readstring = tRead.ReadLine()


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


5) Write your new file(s)

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


6) Close your file
tRead.Close()
 
Share this answer
 
Comments
Madhu158 24-Oct-19 14:08pm    
Hi Scubapro,
Thanks for the code.
I need a small help. My data is getting stored in a text file as ORDER VALUE 123652
& the value(123652 as above) is dynamic.
In that case how can I get it(Order Value) into another text file?

Thanks in advance
Scubapro 25-Oct-19 1:28am    
Hi Madhu158,

You are lucky that my email is still active and valid
after 9 years and I'm still active in IT.

If your textfile is always stored in the same directory,
you could use something like this:

For Each file As String In Directory.GetFiles("Your Directory")
If Path.GetExtension(file).ToLower = ".txt" Then

tRead = IO.File.OpenText(file)
'and so on, but you'll get the idea

End If
Next

Kind regards,
Scubapro.
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
 
Share this answer
 
hi,

i need to write the codes in vb .net
i have looked and searched for answers but all i see is for reading files and extracting any content of that file.
 
Share this answer
 
Comments
Chaegie 15-Jun-10 2:20am    
here it is.. hope you can find some logic on it.

Dim arValues() As String = txtFile.Split(vbcrlf)
For i = 0 To arValues.Count -1
''do some coding here
Next
Hi Scubapro,

thanks for the guide.
:)

i just wanna ask if this would enable me to extract columns of data?
for example, a column for products.
thanks in advance.
 
Share this answer
 
Comments
Scubapro 9-Jun-10 6:47am    
Yes, this is possible if the columns are separated by e.g. chr(09)(horizontal TAB)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900