string and fixnum(float) concatenation....

Discussion in 'Ruby' started by Jun Young Kim, Feb 24, 2009.

  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?
    Jun Young Kim, Feb 24, 2009
    #1
    1. Advertising

  2. Jun Young Kim

    Peña, Botp Guest

    From: Jun Young Kim [mailto:]=20
    #...
    # 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, Feb 24, 2009
    #2
    1. Advertising

  3. Jun Young Kim

    Peña, Botp Guest

    From: Pe=F1a, Botp [mailto:]=20
    #
    # afaik, "*" is used for field widths, eg,

    or precisions

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

    also, if just plain concat, %s will do

    > puts "%s" % [["1", 2]]

    12
    Peña, Botp, Feb 24, 2009
    #3
  4. * Jun Young Kim <> (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
    Simon Krahnke, Feb 24, 2009
    #4
  5. thanks, wrong knowledge is more worse than wrong action.

    2009. 02. 24, =EC=98=A4=ED=9B=84 3:52, Pe=C3=B1a, Botp =EC=9E=91=EC=84=B1:=


    > From: Jun Young Kim [mailto:]
    > #...
    > # 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"
    >
    >



    ***************************
    DSLab, CQ =EA=B9=80=EC=A4=80=EC=98=81 =EB=93=9C=EB=A6=BC
    (02-2082-1091)
    ***************************
    Jun Young Kim, Feb 24, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    3
    Views:
    4,784
    walala
    Sep 18, 2003
  2. bd
    Replies:
    0
    Views:
    604
  3. Carsten Fuchs
    Replies:
    45
    Views:
    1,504
    James Kanze
    Oct 8, 2009
  4. Heesob Park

    Why Fixnum===Fixnum is false?

    Heesob Park, May 13, 2009, in forum: Ruby
    Replies:
    5
    Views:
    110
    Joel VanderWerf
    May 14, 2009
  5. MaggotChild
    Replies:
    6
    Views:
    126
    MaggotChild
    Dec 2, 2009
Loading...

Share This Page