473,466 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

storing delimited string in an array

gh
Hi,
I have a string variable which contains n number of comma delimited
elements and I would like to store each element into an array but I
could not figure how to do it.

for example, 1stitem,2nditem,3rditem,4thitem, ..., nthitem

What would be the best way of storing the above string into an array
like

tempary[0]="1stitem"
tempary[1]="2nditem"
tempary[2]="3rditem"
tempary[3]="4thitem"
....
....
tempary[n-1]="nthitem"

thanks.

May 11 '06 #1
2 2514
gh wrote:
I have a string variable which contains n number of comma delimited
elements and I would like to store each element into an array but I
could not figure how to do it.

for example, 1stitem,2nditem,3rditem,4thitem, ..., nthitem

What would be the best way of storing the above string into an array
like

tempary[0]="1stitem"
tempary[1]="2nditem"
tempary[2]="3rditem"
tempary[3]="4thitem"
...
...
tempary[n-1]="nthitem"


You don't say if these are static values, or you want a general purpose
set of mutable strings.

I typically build a array of pointers to some char arrays (or char
pointers) of sufficient size (determined at runtime or compile time --
your choice depending on your application).

For example, I will often declare a char **, allocated space for the
number of char * items I want to store in it (adding room for one if I
want the notion of the last one in the "list" being null as a marker)
and then allocate room for each string as needed, associating them with
the container pointer "array".

I'm hand-waving here, but think of what "**argv" or "*argv[]" means.
May 11 '06 #2
gh wrote:

I have a string variable which contains n number of comma delimited
elements and I would like to store each element into an array but I
could not figure how to do it.

for example, 1stitem,2nditem,3rditem,4thitem, ..., nthitem

What would be the best way of storing the above string into an array
like

tempary[0]="1stitem"
tempary[1]="2nditem"
tempary[2]="3rditem"
tempary[3]="4thitem"
...
...
tempary[n-1]="nthitem"


Ideally suited for the toksplit() function I published here a short
time ago. But read and heed my sig. below.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
May 11 '06 #3

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

Similar topics

1
by: RelaxoRy | last post by:
Reposted (not sure if got sent) I have results being displayed each with its own checkbox name "selected" and value "id". When someone checks a checkbox, and then continues to page through...
4
by: Arne | last post by:
From: "Arne de Booij" <a_de_booij@hotmail.com> Subject: Comma delimited array into DB problems Date: 9. februar 2004 10:39 Hi, I have an asp page that takes input from a form on the previous...
5
by: CJM | last post by:
In an application I'm working the user has the opportunity to record the despatching of one or more items with serial numbers. For each item they despatch, they have to chose the serial no that...
4
by: Vagabond Software | last post by:
Apparently, the Split method handles consecutive tabs as a single delimiter. Does anyone have any suggestions for handling consecutive tabs? I am reading in text files that contain lines of...
2
by: Ot | last post by:
I have a Tab delimited file: Field1<tab>Field2<tab>...<Field20><crlf> There must be an easy way to break this apart, but I haven't found it yet. Can anyone help? Regards, Ot
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
15
by: VMI | last post by:
I'm parsing a comma-delimited record but I want it to do something if some of the string is between "". How can I do this? With the Excel import it does it correct. I'm using String.Split()....
18
by: Kyro | last post by:
New to C# (migrating from Delphi) and I'm not sure how to get a delimited string into an array of string. input: string looks like - 01-85-78-15-Q11 output: an array with elements - ...
2
by: Jim | last post by:
Hello: I have a variable which contains a comma delimited list contained in a database variable e.g. "5,6,9,10,55,42" - I want to hand this list to an array function to get it to populate an...
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
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,...
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.