![]() |
|
[C#] Split Byte[] Into Chunks - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework) +--- Thread: [C#] Split Byte[] Into Chunks (/Thread-C-Split-Byte-Into-Chunks) |
[C#] Split Byte[] Into Chunks - BlackArray - 06-16-2014 I was developing a Crypter some time ago and I needed to split the payload in-to multiple byte[]. Code: static List<Byte[]> SplitIntoChunks(Byte[] arr_bInput, Int32 iSize)
{
List<Byte[]> lstChunks = new List<Byte[]>();
List<Byte> lstChunk = new List<Byte>();
for(int i = 0; i < arr_bInput.Length; i++)
{
lstChunk.Add(arr_bInput[i]);
if (i == iSize - 1 || i == arr_bInput.Length - 1 )
{
lstChunks.Add(lstChunk.ToArray());
lstChunk.Clear();
}
}
return lstChunks;
}Nothing advanced, but maybe someone needs this. What it does? If you have a Byte[] with Length of 8 and you specify Size to 6 You will then have Two Byte[], one with Size of 6 and the other of 2. RE: [C#] Split Byte[] Into Chunks - ArkPhaze - 06-22-2014 There's better ways to copy blocks of an array to a generic list than to utilize a secondary list instance. |