A range with all the ascii chars

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

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 ?

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.

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

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 ?

(0…0xFFFFFF).each{|i|
a = [i>>16&0xFF, i>>8&0xFF, i&0xFF].pack(“c*”);

    # Now we test if the packing is right
    a.each_byte{|b| print "#{"%02X"%b} "}; puts;}
    # And it is, it outputs:
    # 00 00 00
    # 00 00 01
    # ......
    # FF FF FE
    # FF FF FF

}

YS.

gabriele renzi surrender_it@rc1.vip.lng.yahoo.com writes:

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.

interesting

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

doh!

thanks a lot for Answering so quick

···

On Mon, 16 Dec 2002 14:05:56 +0900, Matt Armstrong matt@lickey.com wrote:

thanks, hat was interesting too

···

On Mon, 16 Dec 2002 23:42:00 +0900, Yohanes Santoso ysantoso@jenny-gnome.dyndns.org wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

gabriele renzi surrender_it@rc1.vip.lng.yahoo.com writes:

(0…0xFFFFFF).each{|i|
a = [i>>16&0xFF, i>>8&0xFF, i&0xFF].pack(“c*”);

   # Now we test if the packing is right
   a.each_byte{|b| print "#{"%02X"%b} "}; puts;}
   # And it is, it outputs:
   # 00 00 00
   # 00 00 01
   # ......
   # FF FF FE
   # FF FF FF

}