I don’t understand why this doesn’t work.
I am using a file to set bunch of in my program. I am reading the content of a file by using separators. My text file looks like this: The Message$1$5001&5002&5003
When I am trying to read a value of a numeric values in my file I am getting error: Input string was not in a correct format. on line: nudInterval.Value = decimal.Parse(setting);
This is how I do it:
if (!lastUsed.EmptyFile())
{
string[] allSettings = lastUsed.Text.Split('$');
int settingCount = 0;
foreach (string setting in allSettings)
{
settingCount++;
if (settingCount == 1)
{
txtText.Text = setting;
}
else if (settingCount == 2)
{
if (setting == "0") tbType.SelectedTab = tbInterval;
else tbType.SelectedTab = tbRange;
}
else if (settingCount == 3)
{
nudInterval.Value = decimal.Parse(setting);
}
else if (settingCount == 4)
{
nudMin.Value = decimal.Parse(setting);
}
else if (settingCount == 5)
{
nudMax.Value = decimal.Parse(setting);
}
}
}
This is because half of your separators are &, not $.
This means you are trying to execute
which will fail.
If those are valid values, you could change your split statement:
or replace & with $ before splitting: