escaping formatting characters in java String.format

a 夏天 提交于 2019-12-05 09:20: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.


回答1:


You can just double up the %




回答2:


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()



来源:https://stackoverflow.com/questions/201312/escaping-formatting-characters-in-java-string-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!