Hi
I am splitting data from an ASCII file generated by another system which has records of a varied format. The first 2 characters in each record are used to indicate the structure of the remaining data in the record. For example:
In the data above, when the first 2 characters are "01" then the format of the remaining record is:
Name (10)
Surname (10)
AddressLine1 (23)
Postcode (4)
When the first 2 characters are "05" then the format of the remaining record is:
AccountNo (7)
ServiceType (10)
StartDate(10)
The above data is very simple. In reality there are many types of records all of varing length and structure depending on the first 2 characters. I only really need to deal with the data as strings- so there's no numeric conversion required.
I had intended to do a giant Select Case statement in order strip out the appropriate parts of the record by substring depending on the first two characters value. However, I was wondering if there was a more maintainable / elegant approach. I was thinking perhaps something more along the lines of using various predefined data structures which map to each record type. I would then be able to read in the record as a string, determine the record type and populate the appropriate data structure in one fell swoop. I have done this kind of operation in other programming languages and wondered if something similar could be done in VB.NET. My investigations into deserializing strings to structures have not been successful.
I would be grateful for your ideas.
Kind regards.
I am splitting data from an ASCII file generated by another system which has records of a varied format. The first 2 characters in each record are used to indicate the structure of the remaining data in the record. For example:
VB.NET:
1 2 3 4 5
12345678901234567890123456789012345678901234567890
---------+---------+---------+---------+---------+
01Jane Smith 12 Aintree Ave 2215
051515302Standard 12-01-2010
01Bob Foster 3 Frond Street 2010
055655154Advanced 12-01-2010
In the data above, when the first 2 characters are "01" then the format of the remaining record is:
Name (10)
Surname (10)
AddressLine1 (23)
Postcode (4)
When the first 2 characters are "05" then the format of the remaining record is:
AccountNo (7)
ServiceType (10)
StartDate(10)
The above data is very simple. In reality there are many types of records all of varing length and structure depending on the first 2 characters. I only really need to deal with the data as strings- so there's no numeric conversion required.
I had intended to do a giant Select Case statement in order strip out the appropriate parts of the record by substring depending on the first two characters value. However, I was wondering if there was a more maintainable / elegant approach. I was thinking perhaps something more along the lines of using various predefined data structures which map to each record type. I would then be able to read in the record as a string, determine the record type and populate the appropriate data structure in one fell swoop. I have done this kind of operation in other programming languages and wondered if something similar could be done in VB.NET. My investigations into deserializing strings to structures have not been successful.
I would be grateful for your ideas.
Kind regards.