Ms_ Dev

Ms_ Dev

  • NA
  • 236
  • 92k

Skip 1st line while reading from csv file.

Oct 18 2016 4:13 AM
Hi Everyone,
 
I have the following code -
  1. static void Main(string[] args)  
  2.        {  
  3.            Console.Clear();  
  4.   
  5.            string fileName = "\\file1.csv";  
  6.   
  7.            fileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + fileName;  
  8.            var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);  
  9.            using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))  
  10.            {  
  11.                string line,ID, UniqNumber;  
  12.                while ((line = streamReader.ReadLine()) != null)  
  13.                {                 
  14.                    ID = line.Length >= 1 ? line.Substring(1,7) : string.Empty;                     UniqNumber = line.Length >= 1 ? line.Substring(8, 12) : string.Empty;  
  15.   
  16.                    Console.WriteLine("ID={0},UniqNumber={1}", ID, UniqNumber);  
  17.                  }  
  18.            }  
  19.            Console.ReadKey();  
  20.        }  
 I want to skip the first row while performing the operation. PLease help to omit the first line as it may contains invalid data.
 
Thanks, 

Answers (4)