String.Format(“”,object)没有对象的格式

时间:2014-06-30 08:20:13

标签: c# string

我们有一个带有attribute-node format的xml节点,如下面的示例所示

<txt field="dateChanged" format="{0:MM/dd/yy}" /> => Datetime
<txt field="duration" format="{0:dd\.hh\:mm\:ss}" /> => Timespan
<txt field="cost" format="{0:0,0.0}" /> => double

我们使用

以正确的格式在pdf上打印txtCanvas.Drawtext( ..... , String.Format(chldNode.Attributes["format"].Value;,data));
<txt field="Description" format="???"> This the productdescription </Description>

我想使用相同的逻辑(并使整个解决方案完全通用)来打印标准文本:

???

获得正确输出必须<txt field="Description" format=""> => Produces empty String 有什么价值?

打印值必须为:此产品说明

{{1}}

感谢您的时间

2 个答案:

答案 0 :(得分:1)

您是否尝试过将{0}用作格式?

<txt field="Description" format="{0}">

答案 1 :(得分:1)

使用{0}作为格式,将String.Format的第一个参数设置为默认格式。