[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-05-19
2
Medium Priority
?
199 Views
Last Modified: 2013-12-17
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
0
Comment
Question by:mohantyd
2 Comments
 
LVL 8

Accepted Solution

by:
RyanAndres earned 500 total points
ID: 24423797

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
 
LVL 9

Expert Comment

by:tculler
ID: 24424280
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question