String.Format(.NET)在Java中是等价的吗? [英] String.Format (.NET) equivalent in Java?

查看:198
本文介绍了String.Format(.NET)在Java中是等价的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET中的String.Format(可能只是VB.NET)将{0},{1},...转换为确定的String,例如:

The String.Format in .NET (maybe just VB.NET) convert {0}, {1}, ... into determined String, for example:

Dim St As String = "Test: {0}, {1}"
Console.WriteLine(String.Format(St, "Text1", "Text2"))

我尝试在Google和StackOverflows中搜索,但它们都返回数字字符串格式。

I've tried to search in both Google and StackOverflows, but they all return number-string format.

推荐答案

其他建议肯定是好的,但更像是 printf 及其谱系,它们是Java最新增加的内容。您发布的代码看起来受到 <$ c $的启发c> MessageFormat

The other suggestions are certainly good, but are more in the style of printf and its lineage which are more recent additions to Java. The code you posted looks to be inspired by MessageFormat.

String format = "Test: {0}, {1}"
System.out.println(MessageFormat.format(format, "Text1", "Text2"))

我不确定'返回:语句是做什么的。

I'm not really certain about what the 'Return: statement is doing though.

这篇关于String.Format(.NET)在Java中是等价的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆