Skip to Content
0
Jan 28, 2019 at 01:14 AM

How can I dynamically parse flat file with nested values?

121 Views Last edit Jan 28, 2019 at 01:18 AM 2 rev

I have a string I need to parse through and load into a table, but the string has multiple levels within it, and no delimiters. For example:

010203040519012717400607081901271740

01 is a device number
02 is the number of reports coming in the string that relate to that device number
03 is report data
04 is report data
05 is report data
1901271740 is the datetime the report was run

I had the series repeat to show the number of reports. Logically it would look like:

01 - Device Number 02 - Number of Reports
First report (03, 04, 05, datetime)
Second report (06, 07, 08, datetime)

The end result in the table I'd like would be

Device Number Report Data1 Report Data2 Report Data3
01 03 04 05
01 06 07 08

The series that contains the number of reports is 44 characters long, then the reports are 40 characters. This repeats, going over 1000 characters. I thought one way to do this would be to create a loop catching the device number and number of reports, setting the number of reports as a counter, then getting the next 40 characters for the number of times in the counter, then repeating this until reaching the end of the string. Would that solution work? Is there a better way?