I'm using CSVHelper, though this seems to occur with the manual methods I know.
I'm trying to create some form of "save data" system using csv files, which will store all important variables that need to be loaded on the program running. Here's my code with generalized variable names:
StringReader csv = new StringReader(SaveData);
var load = new CsvReader(csv);
string convertableString = "";
load.Read();
convertableString = load.GetField(0);
day = Convert.ToInt32(convertableString);
numberOfObjects = load.GetField<int>(1);
for (int i = 0; i < numberOfObjects; i++)
{
load.Read();
myObject[i].objName = load.GetField(0);
myObject[i].objBool = load.GetField<bool>(1);
myObject[i].objInt = load.GetField<int>(2);
}
The lines that convert the strings to other variable types trigger the following error:
System.FormatException: 'Input string was not in a correct format.'
Specifically, the first line to throw this is:
day = Convert.ToInt32(convertableString);
This also applies to CSV Helper's conversion method however, this making the line (note that this requires deletion of the line above it):
day = load.GetField<int>(0);
For the sake of simplicity I'm showing both conversion methods and both return this (upon trying to convert anything, and yes "day" is an int)
My CSV file looks like this:
2,1,
Name, True, 45
I don't claim to have the best knowledge of coding but I'm getting there, though I can't really see what exactly is getting wrong, this isn't even my first time reading csv files and I've never experienced anything like this before.
convertableStringat the lineday = Convert.ToInt32(convertableString);? - RB.