Oke so i read an CSV file with streamreader and get the exception index out of range when it reads an empty line or when the line is not in the correct format.
is there an solution that when you get this error you go to the next line of the csv file
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best approach is to avoid parsing CSV manually at all and use one of the available CSV-readers instead. For example this fast CSV-reader.
Instead of reacting on exceptions i would skip empty lines in the first place.
Instead of a
StreamReaderyou could also useFile.ReadLineswith Linq:If you insist on a
Streamreader: