sprintf

Discussion in 'Java' started by shea martin, Sep 2, 2004.

  1. shea martin

    shea martin Guest

    I know all about the bad things that sprintf in C/C++ can cause. My
    question is, is there a way in java to achieve similar results?

    i.e,

    sprintf(str, "%10s: %.5f\n", var, value);

    I could probably use NumberFormat for the %.5f, but I didn't see
    anything in API's for the %10s. or a %-10s.

    Thanks,

    ~S
     
    shea martin, Sep 2, 2004
    #1
    1. Advertisements

  2. Paul Lutus

    Paul Lutus Guest

    shea martin wrote:

    > I know all about the bad things that sprintf in C/C++ can cause. My
    > question is, is there a way in java to achieve similar results?


    Yes, several.

    >
    > i.e,
    >
    > sprintf(str, "%10s: %.5f\n", var, value);
    >
    > I could probably use NumberFormat for the %.5f, but I didn't see
    > anything in API's for the %10s. or a %-10s.


    Simple justified strings? Why not pad a StringBuffer with spaces to achieve
    the results you want?

    --
    Paul Lutus
    http://www.arachnoid.com
     
    Paul Lutus, Sep 2, 2004
    #2
    1. Advertisements

  3. Tor Iver Wilhelmsen, Sep 2, 2004
    #3
  4. Chris Uppal

    Chris Uppal Guest

    Tor Iver Wilhelmsen wrote:

    > > I know all about the bad things that sprintf in C/C++ can cause. My
    > > question is, is there a way in java to achieve similar results?

    >
    > Yes, if you use 1.5:


    But not if your intent is to do "bad things". If the "similar results" you are
    after are tasty buffer overrun exploits, then I'm afraid you are out of luck
    ;-)

    -- chris
     
    Chris Uppal, Sep 2, 2004
    #4
  5. Alan Moore

    Alan Moore Guest

    On Thu, 02 Sep 2004 06:40:22 GMT, shea martin <>
    wrote:

    >I know all about the bad things that sprintf in C/C++ can cause. My
    >question is, is there a way in java to achieve similar results?
    >
    >i.e,
    >
    >sprintf(str, "%10s: %.5f\n", var, value);


    http://www.braju.com/
     
    Alan Moore, Sep 2, 2004
    #5
  6. shea martin

    shea martin Guest

    shea martin, Sep 3, 2004
    #6
    1. Advertisements

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. Pep
    Replies:
    5
    Views:
    4,264
  2. CJ
    Replies:
    1
    Views:
    1,557
    Davlet Panech
    Oct 28, 2003
  3. Mike Chirico
    Replies:
    2
    Views:
    4,265
    Grumble
    Nov 19, 2003
  4. Pilatus
    Replies:
    3
    Views:
    712
    Pilatus
    Dec 18, 2003
  5. pramod
    Replies:
    22
    Views:
    2,629
    Lew Pitcher
    Jan 6, 2004
  6. james
    Replies:
    6
    Views:
    770
    Rolf Magnus
    Feb 12, 2004
  7. cppaddict

    What to use instead of sprintf?

    cppaddict, Jun 15, 2004, in forum: C++
    Replies:
    5
    Views:
    632
    Misha Polatov
    Jun 17, 2004
  8. William Payne

    sprintf problem

    William Payne, Sep 13, 2004, in forum: C++
    Replies:
    10
    Views:
    3,415
    ma740988
    Sep 15, 2004
Loading...