I have byte[] that represent Packet for example:

byte[] arr = { 01, 02, 03, 04, 05, 06, 07, 08, 09, 10 };

Supposed bytes 03 04 05 represent user name field that i want to change (04, 05 is the user and 03 is the length of all this field) after receive value from user for example:

kinok that translate into 107, 108, 110, 111, 107 so the value inside the packet should change into 06, 107, 108, 110, 111, 107

How can i replace the old value 03 04 05 with the new one 06, 107, 108, 110, 111, 107 ?

有帮助吗?

解决方案

You can change the byte array to a List of byte and do all the changes including inserts there.Then change back.

Details will depend on your situation, e.g. array size and performance issues. The conversions are simple, but not free..

    List<byte> bList = arr.ToList();
    // ...do your changes and inserts...
    arr = bList.ToArray<byte>();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top