Java字符串格式&与参数位置进行本地化
好吧,例如,您有一个要格式化的字符串,例如 “这是%s和%s的字符串” 如果我将其格式化为“约翰”和“艾比”,这将很好地完成工作。 但是,如果相反,我想键入“艾比”,然后键入“约翰”,我可以做到,它不漂亮,看起来像这样: “这是一根弦,由%2 $ s和%1 $ s”,其次是“约翰”,“ abby”的格式,它会格式化它,但我想要的是很多工作(在大文件,仅在运行时格式化多个变量),以确保一切都正确。我的问题是,有没有办法以“漂亮”的方式使其起作用?例如,C#的格式是用“ {0},{1}”完成的,它比Java好一百万倍。
我尝试用正则替代者替换“ {0}”为“%1 $ s”。如果有人可以解决这个问题,它将对我有所帮助,并将对此表示赞赏。提前致谢
Alright, say you have a string you want to format, for example
"this is a string by %s and %s"
and this will do the job just fine if i format it for example with "John" and "Abby"
but, what if instead, I want to type "Abby" and then "John", I can do it, its just not pretty and will look something like this:
"this is a string by %2$s and %1$s" followed by the formatting of "John", "Abby" and it will format it however I want, but the problem with this is its a lot of work (in large files, that are formatted only in runtime with multiple variables) to make sure everything is correct. my question is this, is there a way to have it work in a "prettier" way? for example C#'s formatting is done with "{0}, {1}" which is a million times better than Java's.
I have tried a replacer with regex to replace "{0}" to, for example, "%1$s". if somebody has a solution to this problem it would help me and will be appreciated. thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论