| Author |
A function in Java like string.Format("He is {0}","John") in .NET
|
Nguyen Minh Duc
Greenhorn
Joined: Jan 30, 2006
Posts: 2
|
|
I want a function in Java like string.Format("He is {0}",John) in .NET And the output is "He is John". Please help me. Thanks.
|
I love Java
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
In Java 1.5 has a Formatter class. PrintStream also has a printf method. And the String class also has format method, which would do the same. The format is a bit different though. Not {0}, but C-like stuff. %s, %d, etc... [ February 01, 2006: Message edited by: Satou kurinosuke ]
|
[My Blog]
All roads lead to JavaRanch
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
See java.text.MessageFormat. In Java 5 (JDK 1.5), your example would be MessageFormat.format("He is {0}", "John");
|
[Jess in Action][AskingGoodQuestions]
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
MessageFormat ! Didn't know that one. Thanks
|
 |
 |
|
|
subject: A function in Java like string.Format("He is {0}","John") in .NET
|
|
|