Error Reading from Text File [Lenght 0]
Quicker question, more to the point [sorry for my previous book, wont happen again].
I am reading from a text file and storing peices of each line read into strings.
Code:
while ((line = sr.ReadLine()) != null)
{
string Code = "";
string Description = "";
Code = line.Substring(0,line.IndexOf(" "));
}
The problem occurs when reading the text file, there is a line with Lenght 0 [empty line] and this causes C# to halt with the error "The file could not be read: Length cannot be less than zero.Parameter name: length".
How can I detect this so that the code continues to read until the end of the actual file?
Quicker question, more to the point [sorry for my previous book, wont happen again].
I am reading from a text file and storing peices of each line read into strings.
Code:
while ((line = sr.ReadLine()) != null)
{
string Code = "";
string Description = "";
Code = line.Substring(0,line.IndexOf(" "));
}
The problem occurs when reading the text file, there is a line with Lenght 0 [empty line] and this causes C# to halt with the error "The file could not be read: Length cannot be less than zero.Parameter name: length".
How can I detect this so that the code continues to read until the end of the actual file?
Last edited by a moderator: