On Sun, Feb 27, 2011 at 11:50 AM, rob stanton <tnotnats / gmail.com> wrote:
> I have a binary file in which I'd like to find multiple strings of =A010
> 00 10 00 (hex) amongst all the other values, then following that is a
> name.

ruby-1.9.2-p136 :024 >   content =3D [ 97, 10, 0, 10, 0, 97, 98, 32, 32,
10, 0, 10, 0, 98, 99, 10, 0, 10, 0 ].map(&:chr).join
 =3D> "a\n\x00\n\x00ab  \n\x00\n\x00bc\n\x00\n\x00"
ruby-1.9.2-p136 :025 >
ruby-1.9.2-p136 :026 >   p content.scan(/\n\0\n\0(\w+)/)
[["ab"], ["bc"]]
 =3D> [["ab"], ["bc"]]

should do the trick

If you need the index for some other reason that checking for the
name, let us know that would be a little more work ;).

HTH
Robert
>
> I've found that
>
> contents_array.find_all {|e| e=3D=3D 0x10}
> shows all the 0x10 in the file but not the index, there are several
> hundred.
>
> contents_array.index(0x10)
> shows the first index of 0x10 (242), but how do I go on to list
> subsequent indexes of 0x10?
>
> puts(contents_array[242,4])
> 16
> 0
> 85
> 73
> =3D> nil
>
> shows me that the first 0x10 I find is not correct, i.e. its 10 00 55 49
> so I need to go onto the next 0x10 and test again.
>
> I'm a bit stuck now as to how to do that, I'm very new and finding it
> difficult to find information...
>
> --
> Posted via http://www.ruby-forum.com/.
>
>



--=20
The 1,000,000th fibonacci number contains '42' 2039 times; that is
almost 30 occurrences more than expected (208988 digits).
N.B. The 42nd fibonacci number does not contain '1000000' that is
almost the expected 3.0e-06 times.