bytearray - Removing trailing nulls from byte array in C# -
OK, I'm reading in a file byte array. For some reasons, people who generate these files, at the end of the file, tell about the value of one half manga worthless nail bytes. Does anyone know what's a quick way to trim them at the end?
At first thought that starting from the end of the array and starting again the last time until I found nothing other than a null, but I am surprised that there is no better way.
To answer some questions: Are you sure of 0 bytes in the file, instead there is a bug in the file reading code? Yes, I'm sure of this.
Can you definitely trim all indexed 0s? Yes
Can anybody have any file in the rest of the file? Yes, there may be other places of 0, therefore, no, I can not start at the beginning and can not stop at the first 0.
Now answering additional questions, it seems that you are doing the right thing in the right way Specifically, to touch every byte of the file from the previous 0, to check that it has only 0s.
Now, whether or not you have to copy everything, it depends on what you are doing with the data.
- Perhaps you can remember the index and keep it with the data or the filename.
- You can copy the data into a new byte array
- If you want to "correct" the file, you can shorten the file < / Ul>
"You punching point to each byte and end of file" is the important part.
Comments
Post a Comment