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

P

Pep

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

James

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

Boudewijn Dijkstra

Pep said:
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.
 
R

Roedy Green

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

Pep

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

Joan

Pep said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top