473,413 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Combine byte[]'s

What is the simplest way to combine one byte[] with another?
for example if i have
byte[] header = Encoding.ASCII.GetBytes("this is the header");
and
byte[] body = Encoding.ASCII.GetBytes("this is the body");
how can i combined them into one?

TIA,
Vinny

Dec 28 '05 #1
3 1815

"Vinny Vinn" <Vi*******@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
What is the simplest way to combine one byte[] with another?
for example if i have
byte[] header = Encoding.ASCII.GetBytes("this is the header");
and
byte[] body = Encoding.ASCII.GetBytes("this is the body");
how can i combined them into one?

TIA,
Vinny


:) Here is one way.

byte[] header = System.Text.Encoding.ASCII.GetBytes(
"this is the header"
);
byte[] body = System.Text.Encoding.ASCII.GetBytes(
"this is the body"
);
byte[] contents = new byte[header.Length + body.Length];
Array.Copy(header, 0, contents, 0, header.Length);
Array.Copy(body, 0, contents, header.Length, body.Length);
string s = System.Text.Encoding.ASCII.GetString(contents);
Console.WriteLine(s);

HTH

Mythran

Dec 28 '05 #2
I suppose you mean 'concat' the two buffers ?

byte[] concatBuffer = new byte[header.Length + body.Length];

Buffer.BlockCopy(header, 0, concatBuffer, 0, header.Length);
Buffer.BlockCopy(body, 0, concatBuffer, header.Length, body.Length);
"Vinny Vinn" wrote:
What is the simplest way to combine one byte[] with another?
for example if i have
byte[] header = Encoding.ASCII.GetBytes("this is the header");
and
byte[] body = Encoding.ASCII.GetBytes("this is the body");
how can i combined them into one?

TIA,
Vinny

Dec 28 '05 #3
Thank you Mythran and Luc

"Vinny Vinn" wrote:
What is the simplest way to combine one byte[] with another?
for example if i have
byte[] header = Encoding.ASCII.GetBytes("this is the header");
and
byte[] body = Encoding.ASCII.GetBytes("this is the body");
how can i combined them into one?

TIA,
Vinny

Dec 28 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kee | last post by:
Hi All, I am trying to figure out on how to combine 2 byte array and save to a file. e.g. open "image001.bmp" for binary access write as #1 put #1,,x() & y() close #1 notes : x() and y()...
3
by: Nick | last post by:
I am working a new application...well actually a series of applications for my company. They want internal users to be able to go to a site and everything regarding security is transparent,...
2
by: TJO | last post by:
What is the best way to combine two byte? I am not finding one yet. Thanks
24
by: trint | last post by:
add them into one PrintDocument: PrintDocument pd1 = new PrintDocument(); PrintDocument pd2 = new PrintDocument(); PrintDocument pdCombined = new PrintDocument(); pdCombined = pd1 + pd2;...
1
by: William Stacey [MVP] | last post by:
I need a bullet proof way to combine a root and a relative path to form a FQ rooted path (similar to a VDir in IIS). Path.Combine alone will not do the job in all cases. I also need to be sure...
8
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be...
3
by: Schroeder, AJ | last post by:
Hello group, I am a relative PHP newbie and I am trying to combine two arrays together, but I also need to keep the keys of one array intact. What I am doing is two SNMP walks against a Cisco...
2
by: nugz | last post by:
I want to combine 3 tables with like data then append it with a filter. Tables: NewStarts, Complaints, Memos Combine: Date, Address, Route, Pub, etc.... Then sort: previous 8 days, pub/freq...
2
by: chris | last post by:
I have a few byte arrays that I would like to combine into one array (order needs to be kept). What would be the most efficient way to do this? Thanks for your time, Chris
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.