Solved

csv to single dimmensional array

Posted on 2010-09-20
4
326 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
[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
4 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 333 total points
ID: 33715280
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
ID: 33715281
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 333 total points
ID: 33715321
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
ID: 33751113
Issue Fixed.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 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