Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-05-19
2
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

618 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