473,513 Members | 3,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing Mixed length file lines

I am building a parser to parse out segments, then fields, from atext file. It is possible that not all of the segments/fieldswill be present in each line. I have successfully parsed thefile, but now find that if a line contains "extra" segments thatare not in the previous line they do not parse OR if the segmentappears in the original (1st line) then the same data isrepeated in the next (or all) subsequent lines that do not havethe segment present.

My process for this is
1. To utlize the REGEX Object and parse the segements into an1d Array then take that data and place it into a 2d array (oneindex per row in the file).
2. Put the items from the 2d Array into a dataset.datatable
3. Take the elements form the dataset.datatable and place theminto tables on my SQL Server.

I have tried clearing the values from the 1dArray after postingthem to the 2d Array, but this does not work.

The code segment in question, I believe, follows:

Try
'Step 1: Open the file passed in and Parse the firstline
oReaderSegment = oFileSegment.OpenText(sFileName)
sContent = oReaderSegment.ReadLine()

While sContent <> ""
'Step 2: Identify the pull the segments and loadinto 2d-Array
For Each oMatchSegment InoRegexSegment.Matches(sContent)

'load the segment into the temp stringvariable
sTemp = sContent.Substring(iStart,oMatchSegment.Index - iStart)

'identify the segment being processed
sSegmentID = sTemp.Substring(0, 3)

'get the segment location, 0-9 based on acomplete, all segments being present
'as listed in the Type 17 file specification
iSegmentNumber =SetSegmentLocation(sSegmentID)

'load the segment into the 1d-Array
TempSegmentArray(iSegmentNumber) = sTemp

'increment the index to pull the nextsegment
iStart = oMatchSegment.Index + 1
Next

'Step 3: Copy each line segment into thecorresponding element and line
' in a 2D-Array for further processing
For j = 0 To (TempSegmentArray.Length - 1)
sTemp2 = TempSegmentArray(j)
FinalSegmentArray(i, j) = sTemp2
Next j

'read the next line of the file
sContent = oReaderSegment.ReadLine

'increment the counting variable
i += 1

'reset the the element position variable
iStart = 0
'increment the action control variable

End While

Catch ex As Exception

iError = MsgBox(Err.Number & vbCrLf & Err.Description& vbCrLf & _
"This error occured in the SegmentParser Portion ofthe code", MsgBoxStyle.Critical, "There's Been a Segment ParsingError")

Finally
'Do housekeeping by clearning all objects
oRegexSegment = Nothing
oMatchSegment = Nothing
oMatchesSegment = Nothing
oFileSegment = Nothing
oReaderSegment = Nothing
TempSegmentArray = Nothing

End Try

Thanks for any suggestions.
--------------------------------
From: Michael Tognetti

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>iQmLah/du0qcdmD963K35Q==</Id>
Nov 21 '05 #1
0 984

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

Similar topics

1
2055
by: madhununna | last post by:
I'm trying to parse string data using castor and it looks like the new lines are getting lost. I'm using castor 0.9.4.3 For example: Input <INPUT> First line
8
1707
by: Darius Fatakia | last post by:
Hello, I have a file that I have opened for reading and this file contains lines with several different types of constraint information. For example, here are a few lines: length(0) = 10 Duration of task 0 is 10. needs(16,1) Operation 16 uses resource 1. before(49,9) Operation 49 must be before operation 9.
3
1787
by: Nadav | last post by:
Hi, I am writing a mixed mode application, I have a mixed mode Assembly manipulating a managed byte array, to access this array in unmanaged code I '__pin' the array, As I understand, pining an object guarantee that it will not be collected by the GC ( by increasing it's refcount or so ), Taking that in mind, looking at the code generated by...
18
4832
by: Atara | last post by:
In my apllication I use the following code: '-- My Code: Public Shared Function strDate2Date(ByVal strDate As String) As System.DateTime Dim isOk As Boolean = False If (strDate Is Nothing) Then isOk = False ElseIf Not (strDate.Length() = 6) Then isOk = False
6
2669
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to learn/try a full blown parsing module. My simple script works well until it runs into functions that straddle multiple lines. For example: Call...
9
1971
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an ArrayList? I have tried looping through the logfile using regex, if statements and flags to find the start and end of each message but I do not see a...
3
3293
by: Anup Daware | last post by:
Hi Group, I am facing a strange problem here: I am trying to read xml response from a servlet using XmlTextWriter. I am able to read the read half of the xml and suddenly an exception: “Unexpected end of file while parsing Name has occurred” isbeing thrown. Following is the part o xml I am trying to read: <CHECK_ITEM_OUT>
5
6349
by: tennisfanatic | last post by:
Aloha! I have a data file (.dat) that has about 3000+ lines of data that has the format for the first few characters Position Field Name Length Description 01-14 Item # 9(14) Item Number 15-19 Vendor 9(05) Vender/Manufacturer ID Number 20-44 Model # x(25) Manufacturer Model Number 45-60 UPC...
3
3819
by: Steven Allport | last post by:
I am working on processing eml email message using the email module (python 2.5), on files exported from an Outlook PST file, to extract the composite parts of the email. In most instances this works fine, the message is read in using message_from_file, is_multipart returns True and I can process each component and extract message attachments....
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.