parse a string into a structure
hello all,
I want to take a file-record string (chars and numbers) and parse it into a structure. I can do this in COBOL, how to do it in VB.NET? The file records are fixed lengths and do not change.
COBOL Example:
file-record pic x(150)
rec-specs redefines file-record
rec-id pic 99
pro-date pc x(8)
submitter pic x(50)
process-time pic 9999
etc.
(28 fields total)
VB Example:
structure rec-specs
rec-id as integer
pro-date as string
submitter as string
process-time as integer
etc.
(28 fields total)
end structure
This is a seq. file. One line will be read and processed, this way I can reference the individual elements directly. the problem is how do I define the length of the strings or integers within the structure?
rec-id is always integer length 2 (max # is 99)
pro-date is always string length 8
etc.
Is there an easy way to do this?
Thanks
Sam HobbsPosted Dec 8, 2009, 5:55 PM
First determine if the character data is ASCII or Unicode. That is an important detail. Then determine for sure whether the numbers are actually numbers in the sense of binary or if the nubers are actually number digits in a character format. My COBOL is fuzzy but as best as I remember Pic 9's are actually numbers stored with character digits unless it is packed or something such as that. If the numbers are stored as binary data, then you have a lot more analysis to do; you need to determine exactly how many bytes the data is and if the data is big-endian or little-endian. Data from an IBM "Mainframe" computer stores integer data in reverse order than Intel x86 (Pentium) processors.