Solved

csv to single dimmensional array

Posted on 2010-09-20
4
315 Views
Last Modified: 2013-11-07
Hi

I want to convert CSV file to a single dimmensional array in C#. How can I do that?

Regards
Karan Gupta
0
Comment
Question by:KaranGupta
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 333 total points
Comment Utility
What exactly do you want ? For each line in the csv, 1 item in an array ?

Or in each row of the array, a list of string like example below ?
Building a Simple CSV Parser in C#
http://www.switchonthecode.com/tutorials/building-a-simple-csv-parser-in-csharp
0
 
LVL 22

Assisted Solution

by:Om Prakash
Om Prakash earned 167 total points
Comment Utility
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 333 total points
Comment Utility
A small quick example
using System;

using System.IO;



class Test 

{

    public static void Main() 

    {

        List<string> myFileInArray = new List<string>();

        try 

        {

            // Create an instance of StreamReader to read from a file.

            // The using statement also closes the StreamReader.



            using (StreamReader sr = new StreamReader("TestFile.txt")) 

            {

                string line;

                // Read and display lines from the file until the end of 

                // the file is reached.



                while ((line = sr.ReadLine()) != null) 

                {

                    myFileInArray(line);

                    Console.WriteLine(line);

                }

            }

        }

        catch (Exception e) 

        {

            // Let the user know what went wrong.

            Console.WriteLine("The file could not be read:");

            Console.WriteLine(e.Message);

        }

    }

Open in new window

0
 

Author Closing Comment

by:KaranGupta
Comment Utility
Issue Fixed.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

16 Experts available now in Live!

Get 1:1 Help Now