converting from string to array

Discussion in 'ASP .Net' started by darrel, Jul 25, 2005.

  1. darrel

    darrel Guest

    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
     
    darrel, Jul 25, 2005
    #1
    1. Advertising

  2. Could you not use the array that is returned from Split?

    "darrel" <> wrote in message
    news:ulC$...
    > 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
    >
    >
     
    Peter Rilling, Jul 26, 2005
    #2
    1. Advertising

  3. darrel

    Mark Rae Guest

    "darrel" <> wrote in message
    news:ulC$...

    > 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
    }
     
    Mark Rae, Jul 26, 2005
    #3
  4. darrel

    darrel Guest

    > 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
     
    darrel, Jul 26, 2005
    #4
  5. darrel

    darrel Guest

    > 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
     
    darrel, Jul 26, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Banks

    Converting arraylist to string array

    Andrew Banks, Feb 18, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    26,583
    Martin Dechev
    Feb 18, 2004
  2. Kirby
    Replies:
    3
    Views:
    683
    Kirby
    Oct 8, 2004
  3. cryptogirl
    Replies:
    5
    Views:
    24,953
    cryptogirl
    Feb 25, 2006
  4. Tricky

    Converting Char array to Int array

    Tricky, Feb 4, 2008, in forum: C Programming
    Replies:
    10
    Views:
    969
    Tomás Ó hÉilidhe
    Feb 5, 2008
  5. joy99
    Replies:
    7
    Views:
    855
    Blockheads Oi Oi
    Mar 26, 2011
Loading...

Share This Page