I have a CSV file that I need to open in C# as a sequential file. It has to be parsed by the headers.
As of now I have only figured out how to load the data file as a sequential file using C# System.IO library into an ArrayList structure. Each line in the file has to be a separate record. This is it here:
using System;
using System.IO;
using System.Collections;
namespace FileSearch
{
class Class1
{
static void Main(string[] args)
{
StreamReader objReader = new StreamReader("c:\\Users/Sarah/Desktop/IP4Data.csv"); //open file to read
string sLine = ""; //string variable for data that goes into ArrayList
ArrayList arrText = new ArrayList();
while (sLine != null)
{
sLine = objReader.ReadLine(); //read file one line at a time
if (sLine != null) //if empty, it's null
arrText.Add(sLine);//Add data to Array List
}
objReader.Close(); //end loop
foreach (string sOutput in arrText) //Outputs read data from ArrayList onto screen
Console.WriteLine(sOutput);
Console.ReadLine();
}
}
}
How do I parse the CSV file so it can be searchable in the ArrayList?