473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Splitting a csv string file into a multidemensiona l 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 multidemensiona l 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 4274
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 multidemensiona l 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
1806
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, nultidemensional array which is based on the first array: $dl]]]=$link;
1
5956
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 want this for speed. I know you can increment regular arrays via ++array or array++ etc. etc. but how do you do it with multidemensional arrays? lets say I have array and I need to access array how can I do this without the subscripts? The x and y...
26
808
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 .txt-file in which the data is structured in that way: Project-Nr. ID name lastname 33 9 Lars Lundel 33 12 Emil Korla
3
522
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 .txt-file in which the data is structured in that way: Project-Nr. ID name lastname 33 9 Lars Lundel 33 12 Emil Korla
5
2965
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!) printing the results I expect, which I guess means my dynamic memory allocation is a mess. Also, I was advised previously that I should really free memory in the same place I declare it, but I'm not sure how I would go about doing this in my code...
4
2016
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
3703
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 the data to assign each value to its own variable. So right now I am just saving the data to a txt file and when I look in the text file all the data is there. Not sure if this matters but when I open the text file in Word pad (Rich Text) It...
2
3267
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 lines it worked quite well but srttok isnot working for multiple blank or commas. Can strtok do this kind of splitting if it cant what should i use . Unal
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.