|
-
Apr 6th, 2007, 03:35 PM
#1
Thread Starter
Frenzied Member
[2.0] Remove null bytes from an array?
I have
Code:
byte[] buf = new bytes[256];
bytesrec = TCP.Client.Receive(buf,System.Net.Sockets.SocketFlags.None);
But the problem is when there is a packet sent with less then 256 bytes it has empty bytes on the end. How do i format it to remove those bytes?
-
Apr 7th, 2007, 10:26 AM
#2
Hyperactive Member
Re: [2.0] Remove null bytes from an array?
Hi, I had an old project that used Byte arrays alot, I seem to remember something like you can prefix bytes with a *, ie.
And it will create the array members as you need them.
I don't know if it was that exactly, and I don't know if you're using 256 for a reason (limit size)?
Either way, hope that helps, I'll try to find that project to show you better, more usefull code.
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Apr 7th, 2007, 07:25 PM
#3
Re: [2.0] Remove null bytes from an array?
You don't remove them. A byte array with 256 elements has 256 bytes in it. The idea is that the 'bytesrec' variable contains the number of btes that were actually received. You use that number to know how many elements of the array to actually use. If 'bytesrec' is 256 you know the array is full, otherwise you only use the first 'bytesrec' elements. If you need a full array for some reason then you have to create a new byte array with 'bytesrec' elements and then copy the first 'bytesrec' elements from the original array.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|