Hello,
irb(main):001:0> ?T
=> 84
irb(main):002:0> "\84"
=> "84"
irb(main):003:0> "\124"
=> "T"
irb(main):004:0> "\124\84"
=> "T84"
What? Do these operators not do what I think they should?
Todd
Hello,
irb(main):001:0> ?T
=> 84
irb(main):002:0> "\84"
=> "84"
irb(main):003:0> "\124"
=> "T"
irb(main):004:0> "\124\84"
=> "T84"
What? Do these operators not do what I think they should?
Todd
I think the correct way is not
\number -> char
but
number.chr -> char
65.chr -> "A"
try that:
(1..255).each {|x| puts "#{x} -> #{x.chr}" }
--- Ursprüngliche Nachricht ---
Von: "Todd" <toddkennethbenson@yahoo.com>
An: ruby-talk@ruby-lang.org (ruby-talk ML)
Betreff: ASCII code thing...what gives?
Datum: Wed, 9 Nov 2005 04:57:12 +0900Hello,
irb(main):001:0> ?T
=> 84irb(main):002:0> "\84"
=> "84"irb(main):003:0> "\124"
=> "T"irb(main):004:0> "\124\84"
=> "T84"What? Do these operators not do what I think they should?
Todd
Hi,
irb(main):001:0> ?T
=> 84irb(main):002:0> "\84"
=> "84"irb(main):003:0> "\124"
=> "T"irb(main):004:0> "\124\84"
=> "T84"
8 is too big for octal... So I think the \8 is just ignored, leaving the literal "84".
Regards,
Bill
From: "Todd" <toddkennethbenson@yahoo.com>
That 124 octal equals 84 decimal may be a clue. I don't have my Ruby docs here or I'd look further myself.
On Nov 8, 2005, at 2:57 PM, Todd wrote:
Hello,
irb(main):001:0> ?T
=> 84irb(main):002:0> "\84"
=> "84"irb(main):003:0> "\124"
=> "T"irb(main):004:0> "\124\84"
=> "T84"What? Do these operators not do what I think they should?
Todd
----
Bob Hutchison -- blogs at <http://www.recursive.ca/hutch/>
Recursive Design Inc. -- <http://www.recursive.ca/>
Raconteur -- <http://www.raconteur.info/>
Hello,
irb(main):001:0> ?T
=> 84irb(main):002:0> "\84"
=> "84"irb(main):003:0> "\124"
=> "T"irb(main):004:0> "\124\84"
=> "T84"What? Do these operators not do what I think they should?
84 is 124 in octal.
Hope that helps,
Jeff
On Wed, Nov 09, 2005 at 04:57:12AM +0900, Todd wrote:
Todd
irb(main):001:0> ?T
=> 84
The '?' operator returns the ascii code of the character
irb(main):002:0> "\84"
=> "84"
I think this is evaluated as "\8" and "4". "\x" returns "x" so "84"
makes sense.
Note: there is no decimal substitution only "\nnn" (octal) and "\xnn"
(hex).
irb(main):003:0> "\124"
=> "T"
This matches the octal form a substitution so it is correct.
irb(main):004:0> "\124\84"
=> "T84"
As previously shown the first part matches the octal substitution
"\124" => "T". The second part matches "\8" + "4" => "84". Thus "T84"
is correct.
Dale Martenson wrote:
> irb(main):001:0> ?T
> => 84The '?' operator returns the ascii code of the character
> irb(main):002:0> "\84"
> => "84"I think this is evaluated as "\8" and "4". "\x" returns "x" so "84"
makes sense.Note: there is no decimal substitution only "\nnn" (octal) and "\xnn"
(hex).> irb(main):003:0> "\124"
> => "T"This matches the octal form a substitution so it is correct.
> irb(main):004:0> "\124\84"
> => "T84"As previously shown the first part matches the octal substitution
"\124" => "T". The second part matches "\8" + "4" => "84". Thus "T84"
is correct.
Yes, thanks to everyone for the quick response. I don't even know
where I originally heard of the "\nn" operator, so couldn't find the
doc on it (maybe Pickaxe?).
my_num.chr will work perfect.
Thanks again,
Todd
Todd wrote:
Yes, thanks to everyone for the quick response. I don't even know
where I originally heard of the "\nn" operator, so couldn't find the
doc on it (maybe Pickaxe?).
Programming Ruby (original)
The Ruby Language -> The Basic Types -> Strings
http://www.rubycentral.com/book/language.html#UD
daz