0

我正在四处测试该String#concat(integer)方法。代码如下:

irb(main):006:0> a="hello"
=> "hello"
irb(main):008:0> a<< "world"
=> "helloworld"
irb(main):009:0> a.concat(33)
=> "helloworld!"
irb(main):010:0> a.concat(32)
=> "helloworld! "
irb(main):011:0> a.concat(31)
=> "helloworld! \x1F"
irb(main):012:0> a.concat(34)
=> "helloworld! \x1F\""
irb(main):013:0> a.concat(3)
=> "helloworld! \x1F\"\x03"
irb(main):014:0>

但无法理解——为什么33value 给出helloworld!输出(正确,但不是其他整数)?

为什么/如何 32 给出输出"helloworld! "

以什么方式a << "world"在内部制作字符串?

4

1 回答 1

1

它给你helloworld!是因为!标记的 ASCII 码是 33. Link

于 2013-01-19T17:23:54.317 回答