String and fixnum(float) concatenation


#1

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?


#2

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”


#3

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


#4

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


#5

thanks, wrong knowledge is more worse than wrong action.

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

" 1"

p “%*s” % [2,1]
" 1"

p “%.*s” % [2,“abcdef”]
“ab”


DSLab, CQ 김준영 드림
          (02-2082-1091)