473,395 Members | 1,440 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,395 software developers and data experts.

converting from string to array

well, I've never used arrays and quickly finding that I'm a bit over my
head. I've hit a catch-22 in my understanding of arrays.

I have a comma delimted string that may be of any length:

2, 4, 34

To convert something to an array, it looks like I use the SPLIT command to
populate the array within for/while loop.

But the catch is that to dim an array, it looks like I need to tell it the
number of items I want to store in it to begin with.

So, I'm a bit confused, as SPLIT appears to also make an array. Can I not go
from a split function directly to an array or do I first need to count the
items to dim the array, and then populate it from the split?

-Darrel
Nov 19 '05 #1
8 1286
Could you not use the array that is returned from Split?

"darrel" <no*****@hotmail.com> wrote in message
news:ul**************@tk2msftngp13.phx.gbl...
well, I've never used arrays and quickly finding that I'm a bit over my
head. I've hit a catch-22 in my understanding of arrays.

I have a comma delimted string that may be of any length:

2, 4, 34

To convert something to an array, it looks like I use the SPLIT command to
populate the array within for/while loop.

But the catch is that to dim an array, it looks like I need to tell it the
number of items I want to store in it to begin with.

So, I'm a bit confused, as SPLIT appears to also make an array. Can I not go from a split function directly to an array or do I first need to count the
items to dim the array, and then populate it from the split?

-Darrel

Nov 19 '05 #2
Could you not use the array that is returned from Split?

"darrel" <no*****@hotmail.com> wrote in message
news:ul**************@tk2msftngp13.phx.gbl...
well, I've never used arrays and quickly finding that I'm a bit over my
head. I've hit a catch-22 in my understanding of arrays.

I have a comma delimted string that may be of any length:

2, 4, 34

To convert something to an array, it looks like I use the SPLIT command to
populate the array within for/while loop.

But the catch is that to dim an array, it looks like I need to tell it the
number of items I want to store in it to begin with.

So, I'm a bit confused, as SPLIT appears to also make an array. Can I not go from a split function directly to an array or do I first need to count the
items to dim the array, and then populate it from the split?

-Darrel

Nov 19 '05 #3
"darrel" <no*****@hotmail.com> wrote in message
news:ul**************@tk2msftngp13.phx.gbl...
So, I'm a bit confused, as SPLIT appears to also make an array. Can I not
go
from a split function directly to an array or do I first need to count the
items to dim the array, and then populate it from the split?


Split() does all the work for you - e.g.

string strElements = "1,2,3,4,5,6,7,8";
Array astrElements = strElements.Split(',');
int intArrayLength = astrElements.Length; // returns 8
foreach(string strElement in astrElements)
{
// do something with each element of the array in turn
}
Nov 19 '05 #4
"darrel" <no*****@hotmail.com> wrote in message
news:ul**************@tk2msftngp13.phx.gbl...
So, I'm a bit confused, as SPLIT appears to also make an array. Can I not
go
from a split function directly to an array or do I first need to count the
items to dim the array, and then populate it from the split?


Split() does all the work for you - e.g.

string strElements = "1,2,3,4,5,6,7,8";
Array astrElements = strElements.Split(',');
int intArrayLength = astrElements.Length; // returns 8
foreach(string strElement in astrElements)
{
// do something with each element of the array in turn
}
Nov 19 '05 #5
> Split() does all the work for you - e.g.

string strElements = "1,2,3,4,5,6,7,8";
Array astrElements = strElements.Split(',');
int intArrayLength = astrElements.Length; // returns 8
foreach(string strElement in astrElements)
{
// do something with each element of the array in turn
}


Ah, OK, so it's definitely not as complicated as I thought. That definitely
makes sense that split would dim the array for me with the applicable amount
of items.

Thanks!

-Darrel
Nov 19 '05 #6
> Could you not use the array that is returned from Split?

That's what I'm confused about. When I dim an array, don't I need to tell it
how many items it contains? Or does the split function, by default, dim the
array for me?

-Darrel
Nov 19 '05 #7
> Split() does all the work for you - e.g.

string strElements = "1,2,3,4,5,6,7,8";
Array astrElements = strElements.Split(',');
int intArrayLength = astrElements.Length; // returns 8
foreach(string strElement in astrElements)
{
// do something with each element of the array in turn
}


Ah, OK, so it's definitely not as complicated as I thought. That definitely
makes sense that split would dim the array for me with the applicable amount
of items.

Thanks!

-Darrel
Nov 19 '05 #8
> Could you not use the array that is returned from Split?

That's what I'm confused about. When I dim an array, don't I need to tell it
how many items it contains? Or does the split function, by default, dim the
array for me?

-Darrel
Nov 19 '05 #9

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

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
4
by: x | last post by:
converting 1944 to '1','9','4','4' how can I convert a number such as 1944 to a character array? thanks!
16
by: x | last post by:
converting 1944 to '1','9','4','4' how can I convert a number such as 1944 to a character array? thanks!
2
by: XML newbie: Urgent pls help! | last post by:
Does anyone have a snippet of code that will convert a string to a long array? I've nearly smashed my head against the wall trying to figure this out. I'm Using vb.net 2005 Pls reply asap. I...
4
by: gg9h0st | last post by:
i'm a newbie studying php. i was into array part on tutorial and it says i'll get an array having keys that from member variable's name by converting an object to array. i guessed "i can...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.