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.
Jun Y. Kim (Guest)
on 2009-02-24 08: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?
Peña, Botp (Guest)
on 2009-02-24 08:53
(Received via mailing list)
From: Jun Y. Kim [mailto:removed_email_address@domain.invalid]
#...
# 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"
Peña, Botp (Guest)
on 2009-02-24 08:59
(Received via mailing list)
From: Peña, Botp [mailto:removed_email_address@domain.invalid]
#
# 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
Simon K. (Guest)
on 2009-02-24 09:36
(Received via mailing list)
* Jun Y. Kim <removed_email_address@domain.invalid> (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
Jun Y. Kim (Guest)
on 2009-02-24 09: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.