Results 1 to 5 of 5

Thread: Create array from unknown amount of elements

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188

    Create array from unknown amount of elements

    I am doing a regex match and I want to add the results to a 2 dimensional array where the array, but I do not know how many matches there will be and I don't want to set some insane length for the array. Can someone help me out with this I'm sure its simple.

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try this.
    Code:
    string [,]match = new string[numOfMatches, numOfMatches];

  3. #3
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    Hey,
    if you have a unique value you should use a hashtable. A hashtable always needs a unique key and a matching value for it.

    Heres an example of how to use a hashtable:
    Code:
    .
    .
    .
    using System.Collections;
    .
    .
    .
    Hashtable myTable = new Hashtable();
    myTable.Add("key","value");
    IDictionaryEnumerator em = myTable.GetEnumerator();
    while (em.MoveNext())
    {
    myKeyString = em.Key.ToString()
    myKeyValue = em.Value.ToString()
    }
    .
    .
    .
    Hope I could help!,

    Stephan

    BTW: If you do not have a unique key to use try vector!
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    DevGrp - I dont want to have to loop through the matches just so i can declare the array and loop again. What I'm looking for is like a way to resize the array an not lose the values like VB's ReDim Preserve method.

    Sgt-Peppa - thanks I think that will do.
    Last edited by Tewl; Nov 7th, 2003 at 12:55 PM.

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Try using an ArrayList

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width