Is there a function similar to C++'s sprintf

Discussion in 'Java' started by Pep, Aug 23, 2005.

  1. Pep

    Pep Guest

    I need to create a string from a number of variables taht in C++ I
    would normally use sprintf something like sprintf(target_string,
    formatting_string, variable1, variable2, ...)

    I know that in java 1.5.0 the string class has a formatter but I cannot
    find anything like this in 1.4.2

    So it looks like I am going to have to write a helper function using
    StringBuffer?

    TIA,
    Pep.
     
    Pep, Aug 23, 2005
    #1
    1. Advertising

  2. Pep

    James Guest

    Have a look at java.text.MessageFormat. It is not as convenient as 1.5
    as you have to put the arguments into an array first, but it does the
    job.
     
    James, Aug 23, 2005
    #2
    1. Advertising

  3. "Pep" <> schreef in bericht
    news:...
    >I need to create a string from a number of variables taht in C++ I
    > would normally use sprintf something like sprintf(target_string,
    > formatting_string, variable1, variable2, ...)
    >
    > I know that in java 1.5.0 the string class has a formatter but I cannot
    > find anything like this in 1.4.2
    >
    > So it looks like I am going to have to write a helper function using
    > StringBuffer?


    Some other people have already done that for pre-1.5. I don't know who did it
    or what's it called, though.
     
    Boudewijn Dijkstra, Aug 23, 2005
    #3
  4. Pep

    Roedy Green Guest

    On 23 Aug 2005 03:30:29 -0700, "Pep" <> wrote or
    quoted :

    >
    >I know that in java 1.5.0 the string class has a formatter but I cannot
    >find anything like this in 1.4.2


    There is nothing from sun, but if you scan the web you should find
    lots of home brew attempts at it.

    Every C programmer coming to Java figures it is impossible to code
    without it.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com
     
    Roedy Green, Aug 23, 2005
    #4
  5. Pep

    Pep Guest

    I don't know about impossible but it is certainly a very useful aspect
    of string handling that Java lacks pre 1.5.

    As it is I have managed to convince the powers that be that i can use
    1.5 so my initial problem has gone away though the java implementation
    is a bit raw compared to C/C++ string formatting.

    Cheers,
    Pep.
     
    Pep, Aug 25, 2005
    #5
  6. Pep

    Joan Guest

    "Pep" <> wrote in message
    news:...
    >I don't know about impossible but it is certainly a very useful
    >aspect
    > of string handling that Java lacks pre 1.5.
    >
    > As it is I have managed to convince the powers that be that i
    > can use
    > 1.5 so my initial problem has gone away though the java
    > implementation
    > is a bit raw compared to C/C++ string formatting.
    >
    > Cheers,
    > Pep.


    In particular, what is it that is irritating you?
     
    Joan, Aug 25, 2005
    #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. angus
    Replies:
    3
    Views:
    1,691
    angus
    Jul 8, 2004
  2. =?Utf-8?B?SmF5YnVmZmV0?=

    Is there a way to bind a simple Table or similar to...

    =?Utf-8?B?SmF5YnVmZmV0?=, Feb 23, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    412
    =?Utf-8?B?SmF5YnVmZmV0?=
    Feb 23, 2006
  3. Mike42
    Replies:
    21
    Views:
    17,408
    Chris Uppal
    Nov 14, 2005
  4. questions?

    Are there sprintf in Python???

    questions?, Jan 22, 2007, in forum: Python
    Replies:
    5
    Views:
    372
    Facundo Batista
    Jan 26, 2007
  5. Weng Tianxiang
    Replies:
    7
    Views:
    1,363
    Paul Uiterlinden
    Sep 11, 2009
Loading...

Share This Page