escaping formatting characters in java String.format
Asked Answered
W

2

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.

Waterfowl answered 14/10, 2008 at 14:12 Comment(0)
E
58

You can just double up the %

Escarp answered 14/10, 2008 at 14:14 Comment(0)
Y
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()

Yovonnda answered 14/10, 2008 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.