What is the best way to remove the extra 00-00-00-00-00's from my byte[512]?
Currently when i load it with some data from a received packet that is not 512 bytes it returns something like
Byte[] received = new Byte[512];
int Recieving = Sockitty.ReceiveFrom(received, ref endPoint132);
string dataReceived = BitConverter.ToString(received);
txtReceived.AppendText(dataReceived);
//Outputs the following
74 68 69 73 20 69 73 20 61
20 74 65 73 74 00 68 65 6c
6c 6f 20 00 68 65 72 65 2e
**00** 00 00 00 00 00 00 00 00 //This is the part that needs to be removed but the stared 00.
00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 ... and so on
How can i remove only to the last 00? as you can see there are 00's inside of the packet itself which i don't want to remove.
Would the best way to do it be to reverse and then loop through until it hits something other then 00 and then from then on load it into a new byte array? How would i know what size of an array to load it into?
I'm baffled. Any help appreciated. Thank you!
This overload of Socket.ReceiveFrom
returns the number of bytes read into the array; respect the contents of the array up to this length or, if you really need to, resize the array to this length.