If you already have a byte array that is big enough (i.e. you make it big
enough ahead of time as opposed to appending) you can just use
http://msdn.microsoft.com/library/de...ytestopic2.asp
byte[] Buffer = new byte[Whatever];
System.Text.Encoding.ASCII.GetBytes(YourString, starindex,
YourString.Length, Buffer, wheretostartwritinginthebytearray);
If not then you would have to copy the original array to a larger array then
use a method such as this ...
ex:
static byte [] AppendToBuffer(byte [] _Buffer, string _String) {
byte [] ret = new byte[_Buffer.Length + _String.Length];
Buffer.BlockCopy(_Buffer, 0, ret, 0, _Buffer.Length);
System.Text.Encoding.ASCII.GetBytes(YourString, 0,
YourString.Length, Buffer, _Buffer,Length);
return ret;
}
If you are doing this alot you should probably be using a different type
(such as a memory stream). Which will handle sizing issues for you (or just
use a larger buffer and keep a seperate length for how much you are using)
Cheers,
Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:BB**********************************@microsof t.com...
>I have a string, "-1608" that I need to append to a byte[] variable. How
can
I convert the string to a byte[] so I can append it? thanks.
--
Thanks.