Question How to read from DAT file?

raysefo

Well-known member
Joined
Jul 21, 2010
Messages
207
Programming Experience
Beginner
Hi,

I would like to read data from a DAT file, Is there a way to do it?

Thanks in advance.
 
DAT doesn't really tell anything about the file format, it is a generic file extension short for DATA, which can be anything.
There is however lots of tools in the .Net class library that can read various file content, but you need to know what kind of data you expect to read.
 
DAT is not a universal format. It simply means "data" and lots of programs use ".dat" as an extension for data files in lots of different formats. You need to know the format of the file in order to be able to read it. Once you know the format of the data, then you can read it using a FileStream, BinaryReader, StreamReader or whatever is most appropriate.
 
@jmc: That was kind of unanimous :) and in time sync too. lol
 
Hi,

Thanks for your replies. Here is what I would like to do. I want to implement a windows application that select the file which has data inside and then according to some search criteria, application will display the output.

Thanks in advance.

Best Regards

Sample file format: (there may be multiple of those format below in a single file - Bold ones are the search criterias)
========================================================================================
GAME -> 4101 CPN -> 47449 DRAW -> 821 TEAM ->(0)
INPUT METHOD -> Slip TYPE -> Event
-------------------------------PLAY TRANSACTION DATA-------------------------------
TERMINAL_ID -> 12000101 TRANSACTION -> 152175 TERMINAL TIME -> 30/01/2011 08:42:55
USER -> 120001 CRC -> 8AF035B9 SYSTEM TIME -> 30/01/2011 08:42:59
MULTIPLE DRAWS -> 1 REMAINING DRAWS -> 1 MULTIPLIER -> 2 COLUMNS -> 2
REMAINING ADRAWS -> 0 ADVANCED DRAWS -> 0 AMOUNT -> 42.00
START -> 821 LAST -> 821
STATUS ->Played (001) BARCODE -> 1234567890 1234567890 1234567890 PILOT[0]
Std Event Min Selection Group
335 03 F :2 ---
337 03 F :2 ---
338 03 F :1 ---
345 03 F :1 ---
349 03 U/O:Over ---
354 04 F :2 ---
360 03 U/O:Over ---
355 03 F :1 ---
362 03 F :1 ---
371 03 U/O:Over ---
372 03 F :1 ---
Requests -> 11
Req_Mult -> 001
Revision -> 1 Approval -> 0 Played -> 11

========================================================================================
 
That looks like an arbitrary plain text format to me, so you can use the File class and its ReadAllText or ReadAllLines method, or use the StreamReader class and read line by line with its ReadLine method. System.IO Namespace ()
 
Hi JohnH,

I added something like this to my code:

Dim testTxt As StreamReader = New StreamReader("d:\OUT\" + Label2.Text)
Dim allRead As String = testTxt.ReadToEnd
'Reads the whole text file to the end
testTxt.Close()
Dim regMatch As String = TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text
'string to search for inside of text file. It is case sensitive.
If Regex.IsMatch(allRead, regMatch) Then
Console.WriteLine("found" & vbLf)
Else
Console.WriteLine("not found" & vbLf)
End If

Lets say I search for barcode (1234567890 1234567890 1234567890) and it is matched how can I get the whole data (sample i posted before)???
 
You could split the whole content by the separator string and search each section.
 
Back
Top