Formatting text.

Discussion in 'Ruby' started by Marcin Tyman, Jul 25, 2007.

  1. Marcin Tyman

    Marcin Tyman Guest

    Hi again :)
    Is there any way to format a string. I.E. I've got a variable which may
    be 1, 2, 3 and the variable is added to string. I want to show whole
    string formatted as follows:
    100
    1
    10
    1100

    not like that:
    100
    1
    10
    1100

    Any help would be helpful (as always ;-) )

    thanks in advance
    --
    Posted via http://www.ruby-forum.com/.
     
    Marcin Tyman, Jul 25, 2007
    #1
    1. Advertising

  2. 2007/7/25, Marcin Tyman <>:
    > Hi again :)
    > Is there any way to format a string. I.E. I've got a variable which may
    > be 1, 2, 3 and the variable is added to string. I want to show whole
    > string formatted as follows:
    > 100
    > 1
    > 10
    > 1100
    >
    > not like that:
    > 100
    > 1
    > 10
    > 1100
    >
    > Any help would be helpful (as always ;-) )


    Please look for printf, sprintf and % in the docs. The last one might
    be hard to find. You use it as: "%3d" % 1

    Kind regards

    robert
     
    Robert Klemme, Jul 25, 2007
    #2
    1. Advertising

  3. Marcin Tyman

    Marcin Tyman Guest

    Robert Klemme wrote:
    > 2007/7/25, Marcin Tyman <>:
    >> 100
    >> 1
    >> 10
    >> 1100
    >>
    >> Any help would be helpful (as always ;-) )

    >
    > Please look for printf, sprintf and % in the docs. The last one might
    > be hard to find. You use it as: "%3d" % 1
    >
    > Kind regards
    >
    > robert


    OK, Fine. But... I want to format the string not its output to redirect
    the string to a file on remote machine (the file should be formatted).
    --
    Posted via http://www.ruby-forum.com/.
     
    Marcin Tyman, Jul 25, 2007
    #3
  4. Marcin Tyman wrote:
    > Robert Klemme wrote:


    > > Please look for printf, sprintf and % in the docs. The last one might
    > > be hard to find. You use it as: "%3d" % 1

    >
    > OK, Fine. But... I want to format the string not its output to redirect
    > the string to a file on remote machine (the file should be formatted).


    sprintf and % return a string, they don't print anything to the screen. You
    can write the result of "%3d" % 1 to a file without a problem.


    --
    NP: Katatonia - Fractured
    Ist so, weil ist so
    Bleibt so, weil war so
     
    Sebastian Hungerecker, Jul 25, 2007
    #4
  5. 2007/7/25, Marcin Tyman <>:
    > Robert Klemme wrote:
    > > 2007/7/25, Marcin Tyman <>:
    > >> 100
    > >> 1
    > >> 10
    > >> 1100
    > >>
    > >> Any help would be helpful (as always ;-) )

    > >
    > > Please look for printf, sprintf and % in the docs. The last one might
    > > be hard to find. You use it as: "%3d" % 1
    > >
    > > Kind regards
    > >
    > > robert

    >
    > OK, Fine. But... I want to format the string not its output to redirect
    > the string to a file on remote machine (the file should be formatted).


    Now what? Do you want to output or not? I do not understand your
    remark because with the methods I listed you can do output as well as
    change strings.

    robert
     
    Robert Klemme, Jul 25, 2007
    #5
  6. RnJvbTogTWFyY2luIFR5bWFuIFttYWlsdG86bS50eW1hbkBpbnRlcmlhLnBsXSANCiMgT0ssIEZp
    bmUuIEJ1dC4uLiBJIHdhbnQgdG8gZm9ybWF0IHRoZSBzdHJpbmcgbm90IGl0cyBvdXRwdXQgDQoj
    IHRvIHJlZGlyZWN0IHRoZSBzdHJpbmcgdG8gYSBmaWxlIG9uIHJlbW90ZSBtYWNoaW5lICh0aGUg
    ZmlsZSANCiMgc2hvdWxkIGJlIGZvcm1hdHRlZCkuDQoNCnRoZSBzaW1wbGUgd2F5IGlzIGp1c3Qg
    ZG8gdGhlIG91dHB1dCBvbiBzY3JlZW4gKGluIGEgZm9ybWF0IHlvdSB3YW50KS4gdGhlbiBpZiB5
    b3UncmUgaGFwcHkgd2l0aCB0aGUgb3V0cHV0LCBqdXN0IHJlZGlyZWN0IGl0IHRvIGEgZmlsZS4N
    Cg0KbGlrZSBlZywNCg0KcnVieSBteXRlc3Rwcm9ncmFtLnJiID4gbXlmaWxlDQoNCmp1c3QgdHJ5
    IGl0Lg0KDQpraW5kIHJlZ2FyZHMgLWJvdHANCg==
     
    Peña, Botp, Jul 25, 2007
    #6
  7. Marcin Tyman

    Kaldrenon Guest

    Kaldrenon, Jul 25, 2007
    #7
    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. Winanjaya Amidjojo

    Re: formatting text in textbox while typing

    Winanjaya Amidjojo, Jul 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    430
    Winanjaya Amidjojo
    Jul 3, 2003
  2. ald
    Replies:
    0
    Views:
    358
  3. avnrao
    Replies:
    1
    Views:
    672
    =?Utf-8?B?dG9ueQ==?=
    May 13, 2004
  4. Swanand Mokashi
    Replies:
    0
    Views:
    609
    Swanand Mokashi
    May 13, 2004
  5. Ian
    Replies:
    0
    Views:
    2,223
Loading...

Share This Page