• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What standard class prints messages such as "Hello, my name is {1}"?

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subject says it all. Thanks!
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subject says it all.

Actually, at least for me, it's a bit tricky to interpret just what you're getting at here. Maybe it's me, but I find that it's usually better to supply too much info in questions rather than the opposite.

Perhaps you're looking for the functionality supplied by String.format(....) (or printf as the one calls the other)?

Perhaps you're trying to use another language construct here, to have java print something that is in an ?array? ?on the command line? I'm not sure.

I guess I'm asking you to clarify just what you mean by {1}.

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. I am looking for a standard class that has a method like this:

MyClass.print("Hello, my name is {1}", "Jane");

I don't think printf allows that particular format; I recall someone does.

Thanks.
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jane Dodo wrote:I don't think printf allows that particular format; I recall someone does.

If I recall correctly, this syntax works in C#, but I know of no standard Java classes that use this. I could be wrong though.

Printf will allow:


and the String.format equivalent is:

 
Rob Spoor
Sheriff
Pie
Posts: 20398
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out MessageFormat. However, it's 0 based, so if you cannot change the formats you must provide dummy values for {0}.
 
Jane Jukowsky
Ranch Hand
Posts: 157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yup, that's is. MessageFormat. It's pretty neat I see, even allows for choices and string parsing, and has been there for a while, wonder why it's been so obscure?

Also, I found this in 3rd party resource bundles, wonder how they parse it?

validator.length=length must be between {min} and {max}
floor.out.of.range={floor.name} cannot (escaping #{el}) be {out.of.range}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic