Reputation: 153
What is the best way to parse a file with optional entries?
i.e. I have input of the form
item1,item2,[item3],[item4],item5,item6
where item3 and item4 are both optional entries. I'm currently splitting along the delimiters and filling the objects based on the number of entries given. Is there a better way to make this happen?
Upvotes: 2
Views: 37
Reputation: 21
Here are two options: 1. Rearrange the data so that the optional items are at the end of the file. 2. Pass delimiters for the missing data. This is preferable, as it would allow you to maintain the shape of the data.
Upvotes: 1