From: James Gray Date: 2008-12-21T05:32:08+09:00 Subject: [ruby-core:20731] Re: Working with binary strings in Ruby 1.9? On Dec 20, 2008, at 2:01 PM, Joel VanderWerf wrote: > James Gray wrote: >>> * data[10..20] to extract some bytes efficiently >> data.bytes.to_a[10..20] >>> * and use index and rindex to find bytes. >> data.bytes.to_a.index/rindex > > Is there a way to avoid #to_a? Sure. If the String has an encoding of ASCII-8BIT, as suggested in another response, normal indexing will work. Those will give you Strings instead of Fixnums in 1.9, but unpack() can change that. Note that you don't need to unpack() the entire data String, just the pieces you slice out of it. James Edward Gray II