On Jan 12, 2008, at 3:19 AM, Martin Duerst wrote: > At 05:56 08/01/12, Gary Wright wrote: > >> I believe there was some discussion at one point about having >> String#ord take an argument. I think that would be a nice way to >> request a slice of a binary encoded string: >> >> bin = "\x72\x75\x62\x79".force_encoding('binary') >> bin.ord(0) => 114 >> bin.ord(0..4) => [114, 117, 98, 121] > > Please try bin[0..4].unpack('C*'). Thanks, Martin. Sure that will work but it is ugly and requires an intermediate string creation. Actually it requires two if you count the creation of 'C*'. You've also got the parsing of the format string. That is a lot of overhead simply to map byte(s) to fixnum(s). Actually it might be nice to have String#at(index) to even avoid parsing the argument of String#[] or my proposed #ord Same as Array#at vs. Array#[]. But I guess I would expect str.at(x) to return the same things at str[x] (i.e. another string). Fast indexing of a binary/byte-bucket string is an important use case. Gary Wright