473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Best method to parse this flat file

I need to parse this flat file programmatically.
A group starts with S record and may contain B C P records
T record is for checksum.

What's the best method to do this. Please give me some sample codes to go
along.

Thanks a million

Bill

-----------------------------------------------------------------------------------------------------
S 1 120405050107 144000144000901 901 148COXT 131445219116E0353
EMPTY - MEMO.
B 110 8592+ 8506+ 75 87.0
C 110 78 1792+ 1774+ 7561.7 87.5F265
C 110 78 1791+ 1772+ 7561.7 87.5G265
C 110 78 3581+ 3544+ 7561.7 87.5B265
C 110 78 942+ 932+ 7661.7 87.5F265
C 110 38 107+ 107+ 6551.5113.0F562
C 110 38 107+ 107+ 6651.5113.0G562
C 110 38 216+ 215+ 6651.5113.0B562
C 110 38 56+ 55+ 7651.5113.0F562
S 1 120834050107 144000144000798 798 148COXT 408445341116W0821
EMPTY - MEMO.
B 110 6595+ 6529+ 74 87.0
C 110 78 1697+ 1680+ 7461.7 87.5F265
C 110 78 3581+ 3545+ 7461.7 87.5B265
C 110 78 942+ 933+ 7461.7 87.5F265
C 110 38 102+ 101+ 7351.5113.0F562
C 110 38 216+ 214+ 7351.5113.0B562
C 110 38 57+ 56+ 7451.5113.0F562
B 111 1499+ 1485+ 73 91.0
C 111 79 1414+ 1401+ 7363.3 90.0A166
C 111 38 85+ 84+ 7151.5113.0A562
T 120835050107 115 1291573

May 1 '07 #1
2 3416
So each field seperated by a space will be presentned to you....
this is a snip of code that worked for me.

Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser("C:/testfile.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited

'====space as the delimiter
MyReader.SetDelimiters(" ")

Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String = ""
For Each currentField In currentRow
MsgBox(currentField)
If VB.Left(currentField, 1) = "S" Then
''==do some stuff here <===
End If
If VB.Left(currentField, 5) = "EMPTY" Then
''==do some stuff here <===
End If

.... ETC. .....

If currentField "" Then
currentField = counter & currentField & vbCrLf

My.Computer.FileSystem.WriteAllText("C:/testfile.txt", currentField, True,
ascii)
End If
Next
Catch ex As VB.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
'my.Computer.FileSystem.
End Using

"Bill Nguyen" wrote:
I need to parse this flat file programmatically.
A group starts with S record and may contain B C P records
T record is for checksum.

What's the best method to do this. Please give me some sample codes to go
along.

Thanks a million

Bill

-----------------------------------------------------------------------------------------------------
S 1 120405050107 144000144000901 901 148COXT 131445219116E0353
EMPTY - MEMO.
B 110 8592+ 8506+ 75 87.0
C 110 78 1792+ 1774+ 7561.7 87.5F265
C 110 78 1791+ 1772+ 7561.7 87.5G265
C 110 78 3581+ 3544+ 7561.7 87.5B265
C 110 78 942+ 932+ 7661.7 87.5F265
C 110 38 107+ 107+ 6551.5113.0F562
C 110 38 107+ 107+ 6651.5113.0G562
C 110 38 216+ 215+ 6651.5113.0B562
C 110 38 56+ 55+ 7651.5113.0F562
S 1 120834050107 144000144000798 798 148COXT 408445341116W0821
EMPTY - MEMO.
B 110 6595+ 6529+ 74 87.0
C 110 78 1697+ 1680+ 7461.7 87.5F265
C 110 78 3581+ 3545+ 7461.7 87.5B265
C 110 78 942+ 933+ 7461.7 87.5F265
C 110 38 102+ 101+ 7351.5113.0F562
C 110 38 216+ 214+ 7351.5113.0B562
C 110 38 57+ 56+ 7451.5113.0F562
B 111 1499+ 1485+ 73 91.0
C 111 79 1414+ 1401+ 7363.3 90.0A166
C 111 38 85+ 84+ 7151.5113.0A562
T 120835050107 115 1291573

May 1 '07 #2
Thanks Jim! I'll work on it later.

In the meantime, is there a way to use regular expression with this type of
file?

Thanks again

Bill

"Jim" <Ji*@discussions.microsoft.comwrote in message
news:C4**********************************@microsof t.com...
So each field seperated by a space will be presentned to you....
this is a snip of code that worked for me.

Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser("C:/testfile.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited

'====space as the delimiter
MyReader.SetDelimiters(" ")

Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String = ""
For Each currentField In currentRow
MsgBox(currentField)
If VB.Left(currentField, 1) = "S" Then
''==do some stuff here <===
End If
If VB.Left(currentField, 5) = "EMPTY" Then
''==do some stuff here <===
End If

.... ETC. .....

If currentField "" Then
currentField = counter & currentField & vbCrLf

My.Computer.FileSystem.WriteAllText("C:/testfile.txt", currentField, True,
ascii)
End If
Next
Catch ex As VB.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
'my.Computer.FileSystem.
End Using

"Bill Nguyen" wrote:
>I need to parse this flat file programmatically.
A group starts with S record and may contain B C P records
T record is for checksum.

What's the best method to do this. Please give me some sample codes to go
along.

Thanks a million

Bill

-----------------------------------------------------------------------------------------------------
S 1 120405050107 144000144000901 901 148COXT
131445219116E0353
EMPTY - MEMO.
B 110 8592+ 8506+ 75 87.0
C 110 78 1792+ 1774+ 7561.7 87.5F265
C 110 78 1791+ 1772+ 7561.7 87.5G265
C 110 78 3581+ 3544+ 7561.7 87.5B265
C 110 78 942+ 932+ 7661.7 87.5F265
C 110 38 107+ 107+ 6551.5113.0F562
C 110 38 107+ 107+ 6651.5113.0G562
C 110 38 216+ 215+ 6651.5113.0B562
C 110 38 56+ 55+ 7651.5113.0F562
S 1 120834050107 144000144000798 798 148COXT
408445341116W0821
EMPTY - MEMO.
B 110 6595+ 6529+ 74 87.0
C 110 78 1697+ 1680+ 7461.7 87.5F265
C 110 78 3581+ 3545+ 7461.7 87.5B265
C 110 78 942+ 933+ 7461.7 87.5F265
C 110 38 102+ 101+ 7351.5113.0F562
C 110 38 216+ 214+ 7351.5113.0B562
C 110 38 57+ 56+ 7451.5113.0F562
B 111 1499+ 1485+ 73 91.0
C 111 79 1414+ 1401+ 7363.3 90.0A166
C 111 38 85+ 84+ 7151.5113.0A562
T 120835050107 115 1291573

May 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: chuck amadi | last post by:
Hi , Im trying to parse a specific users mailbox (testwwws) and output the body of the messages to a file ,that file will then be loaded into a PostGresql DB at some point . I have read the...
12
by: jacob nikom | last post by:
Hi, I would like to store XML files in MySQL. What is the best solution: 1. Convert it to string and store it as CLOB/text 2. Serialize it and store as byte array 3. Flatten it out and create...
2
by: Steve_CA | last post by:
Hello all, I just started a new job this week and they complain about the length of time it takes to load data into their data warehouse, which they do once a month. From what I can gather,...
2
by: Brian | last post by:
Hi all, I have an xml document that can contain 248 nodes with each node containing different fields. There is the possibility that there will be more nodes. Each node can have up to 30...
22
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
12
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts...
5
by: Robert W. | last post by:
My app runs perfectly when run in Canada or the U.S. But others are experiencing problems. So I switched my computer to the UK culture and immediately saw a problem. This line was failing: ...
7
by: Gladen Blackshield | last post by:
Hello All! Still very new to PHP and I was wondering about the easiest and simplest way to go about doing something for a project I am working on. I would simply like advice on what I'm asking...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.