A
A
Andrew2016-09-07 10:02:07
C++ / C#
Andrew, 2016-09-07 10:02:07

How to split data from listbox?

Hello!
There is a listbox in it there are data for example 1000 items. How to split this data into N parts and save to files?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Pavlov, 2016-09-07
@DROOMBLE

Extension method for splitting into multiple parts:

using System.Collections.Generic;
using System.Linq;

namespace Helpers
{
    public static class ArrayHelperExtensions
    {
        public static IEnumerable<IEnumerable<T>> Split<T>(this T[] array, int size)
        {
            for (var i = 0; i < (float) array.Length/size; i++)
            {
                yield return array.Skip(i*size).Take(size);
            }
        }
    }
}

Now we take an array and divide it into the required number of parts:
var num = 3;
var parts = listbox1.Items.Split(num);

Then it remains to write to files.
Solution from here .
The specified method is not the fastest, there are faster ways - see here .

A
alex_ak1, 2016-09-07
@alex_ak1

Obviously split and then save.
How do you want to share them? On what basis?

A
Andrew, 2016-09-07
@DROOMBLE

There are no signs! You need to split the listbox data into N files.
For example, in a listbox of 1000 items, they need to be divided into 3 files: i.e. you need to create 1 file with 334 lines of data, the next file with 334, and the last one with 332.
I don't understand how to implement the division algorithm itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question