I am trying to import a file in from my clients custom software. The file is basically a csv file with some custom escape characters in it. I am reading in the file line by line, then splitting each line into a string[]. I am then assigning each each element to a field in my custom object. For example:
Person.Name = line[0];
Person.Age = line[1];
Person.Height = line[2];
etc. The problem is, that some of the files I am importing are from an older version of the app and do not contain all the fields. So this line
Person.Height = line[2];
errors out because line.Length = 2 instead of 3.
Is there a "clean" way of solving this issue? I've gotten around it now by writing an if statement before each assignment to make sure the line[x] is valid, but that just seems kludgy to me.