Extract data from arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?aWxy?=

    Extract data from arrays

    Hi

    This is probably fairly simple but I am newish at programming and was
    wondering if someone can give me some advice on handling the following.

    I have an array with a large number of elements in it. 0-9 are related
    data, 10-19, 20-29 are related and so on. What is the best way of extracting
    groups of elements from the array into another array where each element is
    the related data or to extract say elements 0,1,5 from the first group,
    10,11,15 from the second etc.

    I have tried iterating through the array with if then statements but for a
    large array this gets messy.

    Any advice would be greatly appreciated.

    Regards
    Ian




  • tomb

    #2
    Re: Extract data from arrays

    If the elements are always 10, or some such number, that are related,
    why not use a multi dimensional array instead?

    T

    ilr wrote:
    Hi
    >
    This is probably fairly simple but I am newish at programming and was
    wondering if someone can give me some advice on handling the following.
    >
    I have an array with a large number of elements in it. 0-9 are related
    data, 10-19, 20-29 are related and so on. What is the best way of extracting
    groups of elements from the array into another array where each element is
    the related data or to extract say elements 0,1,5 from the first group,
    10,11,15 from the second etc.
    >
    I have tried iterating through the array with if then statements but for a
    large array this gets messy.
    >
    Any advice would be greatly appreciated.
    >
    Regards
    Ian
    >
    >
    >
    >

    Comment

    • =?Utf-8?B?aWxy?=

      #3
      Re: Extract data from arrays

      Thanks for replying tomb.

      The array is returned from a 3rd pary library so I don't really have much
      choice in that respect.

      "tomb" wrote:
      If the elements are always 10, or some such number, that are related,
      why not use a multi dimensional array instead?
      >
      T
      >
      ilr wrote:
      Hi

      This is probably fairly simple but I am newish at programming and was
      wondering if someone can give me some advice on handling the following.

      I have an array with a large number of elements in it. 0-9 are related
      data, 10-19, 20-29 are related and so on. What is the best way of extracting
      groups of elements from the array into another array where each element is
      the related data or to extract say elements 0,1,5 from the first group,
      10,11,15 from the second etc.

      I have tried iterating through the array with if then statements but for a
      large array this gets messy.

      Any advice would be greatly appreciated.

      Regards
      Ian


      >

      Comment

      • Steven Cheng[MSFT]

        #4
        Re: Extract data from arrays

        Hi Lan

        Sounds like this is an Algorithm question :)

        I'm still not very sure about the exact result you want.

        My understanding is you have a source array which may contains a large
        sequence of elements. And a certain sub sequence of elements in the array
        are of the same group(according to their index in array or their value?)
        and you want to extract them out from the array and make the elements of
        the same group together, correct?

        As Tomb mentioned the "two-dim" array approach, I also think this is a good
        idea if the interval or size of each group are fixed. You can create a
        two-dimensional array in your code and copy all the elements from original
        array into the two dimensional array.

        Also, I think it would be helpful you provide more info such as some
        example data(what's the original array and what you want to make them be
        tranformed into and how you will use them after transformed). Thus, we can
        look for some further ideas on this.

        Sincerely,

        Steven Cheng

        Microsoft MSDN Online Support Lead


        This posting is provided "AS IS" with no warranties, and confers no rights.
        --------------------
        \\
        >From: =?Utf-8?B?aWxy?= <ilr@noemail.no email>
        >References: <F7D66E7C-744A-4E10-8EED-76B4F43EF8BA@mi crosoft.com>
        <_TQqj.68778$Mu 4.64936@bignews 7.bellsouth.net >
        >Subject: Re: Extract data from arrays
        >Date: Thu, 7 Feb 2008 20:39:00 -0800
        \
        >
        >Thanks for replying tomb.
        >
        >The array is returned from a 3rd pary library so I don't really have much
        >choice in that respect.
        >
        >"tomb" wrote:
        >
        >If the elements are always 10, or some such number, that are related,
        >why not use a multi dimensional array instead?
        >>
        >T
        >>
        >ilr wrote:
        Hi
        >
        This is probably fairly simple but I am newish at programming and was
        wondering if someone can give me some advice on handling the following.
        >
        I have an array with a large number of elements in it. 0-9 are
        related
        data, 10-19, 20-29 are related and so on. What is the best way of
        extracting
        groups of elements from the array into another array where each
        element is
        the related data or to extract say elements 0,1,5 from the first
        group,
        10,11,15 from the second etc.
        >
        I have tried iterating through the array with if then statements but
        for a
        large array this gets messy.
        >
        Any advice would be greatly appreciated.
        >
        Regards
        Ian
        >
        >
        >
        >
        >>
        >

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Extract data from arrays

          ilr,

          This is so easy in VB

          \\\
          For i = X To 99 Step 10
          'What you want to do
          Next
          ///

          Cor

          Comment

          • =?Utf-8?B?aWxy?=

            #6
            Re: Extract data from arrays

            Thanks Cor

            I had considered step. Count gives me each 10th value. I was looking to
            group the 10 values together.

            Regards
            ilr

            "Cor Ligthert[MVP]" wrote:
            ilr,
            >
            This is so easy in VB
            >
            \\\
            For i = X To 99 Step 10
            'What you want to do
            Next
            ///
            >
            Cor

            Comment

            Working...