From: "Radosław Bułat" Date: 2011-02-25T18:14:18+09:00 Subject: [ruby-core:35377] [Ruby 1.9 - Feature #4447] add String#byteslice() method Issue #4447 has been updated by Rados��aw Bu��at. Hm, can't you just force it to binary encoding? >> s = "������" => "������" >> s.slice(1,2) => "����" >> s.force_encoding("binary").slice(1,2) => "\x85\xC4" ---------------------------------------- Feature #4447: add String#byteslice() method http://redmine.ruby-lang.org/issues/4447 Author: Suraj Kurapati Status: Open Priority: Normal Assignee: Category: Target version: Please add a String#byteslice() method to the Ruby 1.9 core API. Without that method, I am forced to *inefficiently* perform byte-based string slicing by (1) unpacking the entire string into an Array (with String#unpack or worse: my_string.bytes.to_a) then (2) slicing that Array and finally (3) joining the sliced Array into a string (with Array#pack or worse: my_array.map(&:chr).join), all as shown below: class String unless method_defined? :byteslice ## # Does the same thing as String#slice but # operates on bytes instead of characters. # def byteslice(*args) unpack('C*').slice(*args).pack('C*') end end end Thanks for your consideration. -- http://redmine.ruby-lang.org