Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

[C#] Simple function to merge byte arrays

Very simple function I made to "merge" or append multiple byte arrays, can't find the word for it.

Code
private byte[] mergeBytes(byte[][] inputBytes)
  {
    int tmp = 0;
    byte[] output;

    foreach (byte[] bArr in inputBytes){
    tmp += bArr.Length;
    }

    output = new byte[tmp]; tmp = 0;

    foreach (byte[] bArr in inputBytes){
    Buffer.BlockCopy(bArr, 0, output, tmp, bArr.Length); tmp += bArr.Length;
    }

    return output;
  }

Example usage:

Code
byte[] b = new byte[7]; b = Encoding.Default.GetBytes("UbbeLoL");
    byte[] b2 = new byte[3]; b2 = Encoding.Default.GetBytes("123");
    string str = Encoding.Default.GetString(mergeBytes(new byte[][] { b, b2 })); //<- str = UbbeLoL123
Probably coding some useless shit.
lol when I read the thread title I thought of some sort of compression ^^ nice function anyway I always used array.copy before
(Sep 26, 2010 10:53 AM)pr0t0typ3 Wrote:  lol when I read the thread title I thought of some sort of compression ^^ nice function anyway I always used array.copy before

http://danielvl.blogspot.com/2004/04/use...ad-of.html :)
Probably coding some useless shit.
Can you add [C#] in the Title?
It becomes a bit misleading.
:/
(Sep 26, 2010 11:06 AM)iDope -.- Wrote:  Can you add [C#] in the Title?
It becomes a bit misleading.
:/

I thought it don't make any difference if it's C# or vb.net as this code isn't really hard to convert just run it through an online code convert or something.

But I guess i'll change the title though if it's really that "misleading".
Probably coding some useless shit.
Not that it ain't that simple to conbvert the code, but yeah, still..It's better to be clear..
:)
Nice share nevertheless.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by pzychonautJun 8, 2023 05:03 PM 5 177 Jun 8, 2023 05:03 PM
Last Post: padrino
[C] by EmacsSucksButILikeItJun 4, 2022 11:03 PM 1 222 Jun 4, 2022 11:03 PM
Last Post: unazed
[C#] by Julius013Mar 2, 2022 05:12 PM 4 313 Mar 2, 2022 05:12 PM
Last Post: Julius013