Forum: Ruby string and fixnum(float) concatenation....

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7caba80fca2ac4ddbb7f55957e5c0dec?d=identicon&s=25 Jun Young Kim (Guest)
on 2009-02-24 07:14
(Received via mailing list)
hi, forks...

see this source

irb(main):015:0> puts "%*s" % [ "1", 2 ]
TypeError: can't convert String into Integer
  from (irb):15:in `%'
  from (irb):15
  from :0
irb(main):016:0>

AIK, "%*s" is to use for concatenation of array.

but, I met the previous error message.

What's different ways I can take?
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2009-02-24 07:53
(Received via mailing list)
From: Jun Young Kim [mailto:jykim@altibase.com]
#...
# AIK, "%*s" is to use for concatenation of array.

can you point me a link to that info?


afaik, "*" is used for field widths, eg,

> p "%*s" % [2,"1"]
" 1"

> p "%*s" % [2,1]
" 1"

> p "%.*s" % [2,"abcdef"]
"ab"
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2009-02-24 07:59
(Received via mailing list)
From: Peña, Botp [mailto:botp@delmonte-phil.com]
#
# afaik, "*" is used for field widths, eg,

or precisions

#
# > p "%*s" % [2,"1"]
# " 1"
#
# > p "%*s" % [2,1]
# " 1"
#
# > p "%.*s" % [2,"abcdef"]
# "ab"
#

also, if just plain concat, %s will do

> puts "%s" % [["1", 2]]
12
1d53b088a989e069b94597c282eebbbc?d=identicon&s=25 Simon Krahnke (Guest)
on 2009-02-24 08:36
(Received via mailing list)
* Jun Young Kim <jykim@altibase.com> (07:13) schrieb:

> irb(main):015:0> puts "%*s" % [ "1", 2 ]
> TypeError: can't convert String into Integer
>   from (irb):15:in `%'
>   from (irb):15
>   from :0
> irb(main):016:0>

Maybe you meant "%*s" % [ 2, "1" ] if you expect " 1".

mfg,             simon .... l
7caba80fca2ac4ddbb7f55957e5c0dec?d=identicon&s=25 Jun Young Kim (Guest)
on 2009-02-24 08:52
(Received via mailing list)
thanks, wrong knowledge is more worse than wrong action.

2009. 02. 24, 오후 3:52, Peña, Botp 작성:

> " 1"
>
>> p "%*s" % [2,1]
> " 1"
>
>> p "%.*s" % [2,"abcdef"]
> "ab"
>
>


***************************
    DSLab, CQ 김준영 드림
              (02-2082-1091)
***************************
This topic is locked and can not be replied to.