0

Hello,
Im trying to read a CSV into a 2d array, where the rows of CSV are the rows of the array, and the columns are defined by the separating commas in the file. It will be a rectangular array.
any help would be ace!
thankys

3
Contributors
3
Replies
14
Views
7 Years
Discussion Span
Last Post by Member 785500
0

You can read the file contents in line by line then use string.Split() to convert each row into a string array.
The following works provided that the array definitely has the same number of rows as columns:

string filePath = @"C:\Users\Dan\Documents\test.txt";
            StreamReader sr = new StreamReader(filePath);
            string[,] strArray = null;
            int Row = 0;
            while (!sr.EndOfStream)
            {
                string[] Line = sr.ReadLine().Split(',');
                if (Row == 0)
                {
                    strArray = new string[Line.Length, Line.Length];
                }
                for (int column=0; column<Line.Length; column++)
                {
                    strArray[Row, column] = Line[column];
                }
                Row++;
            }
0

it showing error

java.lang.ArrayIndexOutOfBoundsException: 1
at CVSToXML.main(CVSToXML.java:70)

I want to add contents values

english.addElement("pubDate").addText(gender);
english.addElement("dicription").addText(gender);
english.addElement("link").addText(gender);
please help me

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.