joutvhu / fixed-width-parser

Fixed Width Parser: parse fixed width string to object and export object to fixed width string
MIT License
15 stars 3 forks source link

Parsing fixed width string with variable segments #34

Open jaysara opened 5 months ago

jaysara commented 5 months ago

I have a variable segments structure like,

A001{field1-2character}{field2-12characters}{field3-21characters}C001{field4-1character}{field5-10characters}{field6-13characters}D001{field7-12character}{field8-2characters}{field9-21characters}

another string can be

A001{field1-2character}{field2-12characters}{field3-21characters}B001{field11-5characters}{field12-8characters}{field13-3characters}D001{field7-12character}{field8-2characters}{field9-21characters}E001{field20-5characters}{field21-12characters}{field22-2characters}

As mentioned we have segments like A001, B001 , C001, D001, etc.. All segments have fixed format fields. However some segments may or may not be present in a given string. The parser needs to figure out whether a segment is there or not and execute parser logic specific to the segment.