gabriele renzi <surrender_it / rc1.vip.lng.yahoo.com> writes:

> Hi, gurus
>
> I know that ruby handles unicode, and I suppose it handles ascii as a
> subset of unicode, m need is to have a Range like
> "\000\000\000".."\255\255\255"   [1]
>
> or, if you like, this more:
> "aaa".."zzz"+$all_the_strange_chars

Ranges use Object.succ to get to get from the first element to the
last.  String.succ will not eventually increment "\000\000\000" to
"\255\255\255" -- it has different semantics that make it useful
mainly for generating successively unique strings.

Note, in strings "\255" is an octal number that is 173 decimal.  You
want "\377" for 255 decimal.

> I tried to use the previous [1] way to obtain this, but it seems to
> fail, giving me an array with 58 (!) elements.  How could I iterate
> over strings like this ?

a = []
0.upto(255) { |c1|
  0.upto(255) { |c2|
    0.upto(255) { |c3|
      a << [c1, c2, c3].pack("c*")
    }
  }
}

A mighty big array.