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. Advertising

  2. shea martin

    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. Advertising

  3. Tor Iver Wilhelmsen, Sep 2, 2004
    #3
  4. shea martin

    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. shea martin

    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. 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. Pep
    Replies:
    5
    Views:
    4,075
  2. CJ
    Replies:
    1
    Views:
    1,338
    Davlet Panech
    Oct 28, 2003
  3. Mike Chirico
    Replies:
    2
    Views:
    3,856
    Grumble
    Nov 19, 2003
  4. Pilatus
    Replies:
    3
    Views:
    549
    Pilatus
    Dec 18, 2003
  5. pramod
    Replies:
    22
    Views:
    1,860
    Lew Pitcher
    Jan 6, 2004
Loading...

Share This Page