C#:php sprintf等价物

C#:php sprintf等价物,c#,php,equivalent,string-formatting,C#,Php,Equivalent,String Formatting,我正在为php sprintf函数寻找一个C#等价物 我有下面的字符串: "There are %s hits, %s are an exact match." 我希望用查询返回的数字替换%s。在php中,我将执行以下操作: $res = sprintf("There are %s hits, %s are an exact match", $number1, $number2); 我如何在C#中实现这一点?我考虑过string.replace(),但这只适用于1件需要更换的物品。在这种情况

我正在为php sprintf函数寻找一个C#等价物

我有下面的字符串:

"There are %s hits, %s are an exact match."
我希望用查询返回的数字替换
%s
。在php中,我将执行以下操作:

$res = sprintf("There are %s hits, %s are an exact match", $number1, $number2);
我如何在C#中实现这一点?我考虑过
string.replace()
,但这只适用于1件需要更换的物品。在这种情况下,您要查找的有多个。

格式说明符与PHP中的略有不同

您可以使用


两个答案之间的20秒会产生如此大的差异,真是不可思议=/
String myStr = String.Format("There are {0} hits, {1} are an exact match",
                              number1, number2);
string s = String.Format("There are {0} hits, {1} are an exact match", number1, number2);