I have a problem with getting parts of the ByteArray data.
There is a binary text in fileData:
var fileData:ByteArray = new ByteArray();
//..........here's code that fills this var with binary data
.....readBytes(fileData,0,1000);
//
Data is like this:
йYЯyeSВ–нkq(г<<<start>>>:xЪмЅdf”cйxЪsdfмЅ”cйdxЪмЅ”cй<<<end>>>В–нkВ
So, I need to find position of <<< start >>> and <<< end >>> and copy data, that is between them.
But searching fileData.toString().indexOf('<<< start >>>') sometimes gets wrong position of this string, and sometimes can’t find it at all.
What can I do to correctly determine the position of part of the data that I need?
You should not use
fileData.toString().indexOf()since you are working with binary data. You have to search a sequence of bytes.The following function retrieve the position of a specified pattern:
Then you can use the function this way:
Disclaimer: I haven’t tested my code!