Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

csv to single dimmensional array

Posted on 2010-09-20
4
Medium Priority
?
328 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 1332 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 668 total points
ID: 33715281
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 1332 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

730 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