StreamReader ReadFile;
ReadFile = File.OpenText("..\\..\\WeatherForecasts.txt");
string line = ReadFile.ReadLine();
if (String.IsNullOrEmpty(line) == false)
{
txtCity.Text = Regex.Replace(ReadFile.ReadLine(), "City: ", String.Empty);
dateTimePicker1.Value = DateTime.Parse(Regex.Replace(ReadFile.ReadLine(), "Date: ", String.Empty));
MinT.Value = decimal.Parse(Regex.Replace(ReadFile.ReadLine(), "Minimum temperature: ", String.Empty));
MaxT.Value = decimal.Parse(Regex.Replace(ReadFile.ReadLine(), "Maximum temperature: ", String.Empty));
Prec.Value = decimal.Parse(Regex.Replace(ReadFile.ReadLine(), "Precipitation: ", String.Empty));
Humidity.Value = decimal.Parse(Regex.Replace(ReadFile.ReadLine(), "Humidity: ", String.Empty));
WindSpeed.Value = decimal.Parse(Regex.Replace(ReadFile.ReadLine(), "Wind Speed: ", String.Empty));
}
ReadFile.Close();
actually this is working but if any data is stored in WeatherForecasts.txt
I get this error message:
System.FormatException: 'The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.'
so I changed like
Regex.Replace(ReadFile.ReadLine(), "City: ", String.Empty);
Regex.Replace(ReadFile.ReadLine(), "Date: ", String.Empty);
Regex.Replace(ReadFile.ReadLine(), "Minimum temperature: ", String.Empty);
Regex.Replace(ReadFile.ReadLine(), "Maximum temperature: ", String.Empty);
Regex.Replace(ReadFile.ReadLine(), "Precipitation: ", String.Empty);
Regex.Replace(ReadFile.ReadLine(), "Humidity: ", String.Empty);
Regex.Replace(ReadFile.ReadLine(), "Wind Speed: ", String.Empty);
and I got a different error
System.ArgumentNullException: 'Value cannot be null.
Parameter name: input'
if i don't store data, it works perfectly.
and this is what data is stored in WeatherForecasts.txt now
City: dddd
Date: 5/27/2020 12:00:00 AM
Minimum temperature: 1
Maximum temperature: 1
Precipitation: -1
Humidity: -2
Wind Speed: 1
sorry, I don't know what you need, so if you need any other information, please tell me.