473,549 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1824

"Vinny Vinn" <Vi*******@disc ussions.microso ft.com> wrote in message
news:84******** *************** ***********@mic rosoft.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.Enc oding.ASCII.Get Bytes(
"this is the header"
);
byte[] body = System.Text.Enc oding.ASCII.Get Bytes(
"this is the body"
);
byte[] contents = new byte[header.Length + body.Length];
Array.Copy(head er, 0, contents, 0, header.Length);
Array.Copy(body , 0, contents, header.Length, body.Length);
string s = System.Text.Enc oding.ASCII.Get String(contents );
Console.WriteLi ne(s);

HTH

Mythran

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

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

Buffer.BlockCop y(header, 0, concatBuffer, 0, header.Length);
Buffer.BlockCop y(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
9504
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() contains bitmap binary data.
3
2701
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, however we will have brokers and customers that also need to connect and will require a username and password. In this case we were going to store their...
2
8187
by: TJO | last post by:
What is the best way to combine two byte? I am not finding one yet. Thanks
24
8133
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; pdCombined.Print(); Thanks, Trint
1
5840
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 the no funny business can go on in the passed "path" that would produce a path not in the root (i.e. "..\..\dir1"). Here is my first stab at it, but...
8
4575
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 an easy task but it just isn't clicking. For some reason, the preserve doesn't seem to be working.
3
8199
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 router in which I expect the script to return the interface number along with a small description of the interface type, like this: Array (
2
2358
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 for that day etc... I can already do the append filter, but I cant combine and then append. I tried a Union and did the combine.. but lack the...
2
7895
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
0
7527
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.