Adding a string to an existing byte array
-
While I'm sure I could easily work out something to do this, I was wondering if there was a function that would add an array of bytes to the end of an existing byte array. Specifically, I am working on a project where a method takes a byte array as a parameter, where the byte array contains more than just a converted string. Original C/C++ sample code:
unsigned char buf[10];
int len = 10;buf[0] = 9;
buf[1] = 76;
sprintf((char*)&buf[2], "%d", groupnum);I'm sure the answer is obvious, but it's just not hitting me in the face right at the moment. :~ (For those interested, this is an example from Avaya's "IP Office TAPI Link Developer's Guide" to build the parameter block for the lineDevSpecific function of TAPI 2.x. I'm working on the project in VB.NET using JulMar's ATAPI.NET wrapper. I'm having another issue with the function call to use the byte array, but that's another matter entirely.)
-
While I'm sure I could easily work out something to do this, I was wondering if there was a function that would add an array of bytes to the end of an existing byte array. Specifically, I am working on a project where a method takes a byte array as a parameter, where the byte array contains more than just a converted string. Original C/C++ sample code:
unsigned char buf[10];
int len = 10;buf[0] = 9;
buf[1] = 76;
sprintf((char*)&buf[2], "%d", groupnum);I'm sure the answer is obvious, but it's just not hitting me in the face right at the moment. :~ (For those interested, this is an example from Avaya's "IP Office TAPI Link Developer's Guide" to build the parameter block for the lineDevSpecific function of TAPI 2.x. I'm working on the project in VB.NET using JulMar's ATAPI.NET wrapper. I'm having another issue with the function call to use the byte array, but that's another matter entirely.)
I have no idea what you're getting at,but you may want to look into the System.Text.StringBuilder class.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
While I'm sure I could easily work out something to do this, I was wondering if there was a function that would add an array of bytes to the end of an existing byte array. Specifically, I am working on a project where a method takes a byte array as a parameter, where the byte array contains more than just a converted string. Original C/C++ sample code:
unsigned char buf[10];
int len = 10;buf[0] = 9;
buf[1] = 76;
sprintf((char*)&buf[2], "%d", groupnum);I'm sure the answer is obvious, but it's just not hitting me in the face right at the moment. :~ (For those interested, this is an example from Avaya's "IP Office TAPI Link Developer's Guide" to build the parameter block for the lineDevSpecific function of TAPI 2.x. I'm working on the project in VB.NET using JulMar's ATAPI.NET wrapper. I'm having another issue with the function call to use the byte array, but that's another matter entirely.)
Use the
Array.Copy
orArray.CopyTo
method to copy the data from one array into another array. Use theEncoding.GetBytes
method to encode a string into a byte array. Example:byte[] group = Encoding.UTF8.GetBytes(groupNumber.ToString());
Despite everything, the person most likely to be fooling you next is yourself.
-
Use the
Array.Copy
orArray.CopyTo
method to copy the data from one array into another array. Use theEncoding.GetBytes
method to encode a string into a byte array. Example:byte[] group = Encoding.UTF8.GetBytes(groupNumber.ToString());
Despite everything, the person most likely to be fooling you next is yourself.
Array.CopyTo is exactly what I was looking for. :)