24

This question is pretty much the same as this .Net question exept for java.

How do you escape the %1$ characters in a java String.format?

THe reason I need to do this is that I'm building up a string that will later have more info inserted into it. I've thought of having one of the args just be "%1$" but that doesn't seem to be very elegant?

sorry if this is obvious my java is a tad rusty.

2 Answers 2

58

You can just double up the %

Sign up to request clarification or add additional context in comments.

Comments

0

Either you can use the proposal of Draemon, either you can also have a look at java.text.MessageFormat class that has more powerfull formatting abilities than String.format()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.