Solved

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

Posted on 2009-05-19
2
190 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 125 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now