How to get comma separated values of Log file and store in array

i have huge log file with all element comma(,) separated. I need to read line by line in c#  .net and store each values in array.

Can any one suggest the best code in c# to do this
mohantydAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RyanAndresConnect With a Mentor Commented:

StreamReader reader = new StreamReader("file.txt");
 
string line;
while ((line = reader.ReadLine()) != null)
{
    string[] lineParts = line.Split(',');
    //  Do what you want with lineParts array.
}

Open in new window

0
 
tcullerCommented:
I don't see anything wrong with the above, but I can suggest an alternative. Also, I'm assuming your file is line-delimited, and within the lines, it is comma delimited. If the comma-delimited values belong to the line, you can use this, instead:

private System.String[][] OrganizeFile(System.String myFilePath)
{
	System.String[] temp = System.IO.File.ReadAllLines(myFilePath);
	System.String[][] output = new System.String[temp.Length][];
 
	for(System.Int32 i = 0; i < temp.Length; i++)
	{
		output[i] = temp[i].Split(',');
	}
 
	// The first "index" indicates the line, while the second indicates each value.
	return output;
}

Open in new window

0
All Courses

From novice to tech pro — start learning today.