I'm parsing a CSV file in a c# .net windows form app, taking each line into a class I've created, however I only need access to some of the columns AND the files being taken in are not standardized. That is to say, number of fields present could be different and the columns could appear in any column.
My solution to this was to ask the user to enter the columns required and set as strings.
string standard = "";
string name = "";
string efficiency = "";
user would then enter a value from A to ZZ.
I then instantiated ints to correspond with the entries:
int standardLocation = 0;
int nameLocation = 0;
int efficiencyLocation = 0;
and finally once the form is submitted. the ints get their final value by running through an if else... statement:
if(standard == "A")
{
standardLocation = 0;
}
else if(standard == "B")
{
standardLocation = 1;
}
...
etc running all the way to if VAR1 == ZZ and then the code is repeated for VAR2 and for VAR3 etc..
I'm very new to this and I'm hoping there has got to be a significantly better way to achieve this. I'm thinking some kind of lookup table maybe, but i cant figure out how to implement this, any pointers on where i could look?
Aucun commentaire:
Enregistrer un commentaire