E3p*_*3pO 2 c# arrays null byte trim
从我的字节[512]中删除额外00-00-00-00-00的最佳方法是什么?
目前,当我从一个不是512字节的接收数据包中加载一些数据时,它会返回类似的内容
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
Run Code Online (Sandbox Code Playgroud)
我怎样才能删除到最后一个00?正如你所看到的,数据包本身内部有00,我不想删除.
最好的方法是反转然后循环,直到它遇到00以外的其他东西,然后从那时加载到新的字节数组?我怎么知道加载它的数组的大小?
我很困惑.任何帮助赞赏.谢谢!
这个重载Socket.ReceiveFrom返回读入数组的字节数; 将数组的内容保持到此长度,或者,如果确实需要,请将数组的大小调整为此长度.
| 归档时间: |
|
| 查看次数: |
5682 次 |
| 最近记录: |