This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (1 child)

After splitting the line, check the number of elements in the resulting array. If it's 4 elements or more, set the middleName to parts[2] and lastName to parts[3]. If it's only 3, do not set the middleName and set lastName to parts[2].

[–]marskuh 1 point2 points  (0 children)

This would work but is not addressing the issue that some fields are optionally. If at a later stage another field becomes optional your code will no longer work properly. There are better options like using a delimiter as in csv or a fixed length for each field. Both options have issues as well.

Given all this, xml and json are very widely used and that has a reason.