473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Splitting a csv string file into a multidemensional array

Hi

To split a single string we do the following
#
myString= "bannana, bowling balls, juice"
string singleArray[]= myString.split(',');
#
This gives
singleArray[1] = "bannana" etc.

But to split a string into a multidemensional array is more complex.
The Arraylist() method has been shown but how do you do it using
generics or other manner?

myString= "bannana, box, bowling balls, crate, juice, bottle"

I want to split this up where each element goes to row and column
alternating to give a 2 dimensional array:
Bannana, Box
Bowling balls, crate
juice, bottle
teeth, mouth

i.e. MultiArray[2,0] = "teeth" and MultiArray[2,1] = "mouth"
Any ideas?

Thanks in advance

Mar 22 '07 #1
2 4257
On Mar 22, 1:11 pm, "Perseus" <hollywoods...@gmail.comwrote:
Hi

To split a single string we do the following
#
myString= "bannana, bowling balls, juice"
string singleArray[]= myString.split(',');
#
This gives
singleArray[1] = "bannana" etc.

But to split a string into a multidemensional array is more complex.
The Arraylist() method has been shown but how do you do it using
generics or other manner?

myString= "bannana, box, bowling balls, crate, juice, bottle"

I want to split this up where each element goes to row and column
alternating to give a 2 dimensional array:
Bannana, Box
Bowling balls, crate
juice, bottle
teeth, mouth

i.e. MultiArray[2,0] = "teeth" and MultiArray[2,1] = "mouth"
Any ideas?

Thanks in advance
Could you just split on the newline giving a string for each line,
then iterate through them and split on the comma?

string [] lines = myString.Split("\n");
foreach(stirng line in lines) {
2dArray[i++] = line.split(',');
}

Just my first thought... (I realize there is stuff missing from that
code)

Cheers,
--Rob W

Mar 22 '07 #2
On Mar 22, 1:11 pm, "Perseus" <hollywoods...@gmail.comwrote:
Hi

To split a single string we do the following
#
myString= "bannana, bowling balls, juice"
string singleArray[]= myString.split(',');
What happens when a data element spans multiple lines? What happens
when a data element itself contains commas, and (hence) is quoted?

Both of these are valid csv possibilities.

cdj

Mar 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Red | last post by:
I have an array which is dynamically generated by parsing a web page: titles Array ( => bookmarks => New Folder => New Folder2 ) and I want to insert html links into another,...
1
by: Hendrix | last post by:
Hi, I would like to pick four elements from a multidemensional array and use the content of those elements. I want to do this without all the subscript calls required for individual access, just...
26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i donīt have a lot of success. Can anybody help me (and understand my english :-))? I have a...
3
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i donīt have a lot of success. Can anybody help me (and understand my english :-))? I have a...
5
by: fatted | last post by:
I'm trying to write a function which splits a string (possibly multiple times) on a particular character and returns the strings which has been split. What I have below is kind of (oh dear!)...
4
by: JeffM | last post by:
Quick C# question: I have comma delimited values in a string array that I want to pass to seperate variables. Any tips on splitting the array? Thanks in advance! JM
20
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.