如何在C#字符串格式函数Razor中添加多个空格?

如何在C#字符串格式函数Razor中添加多个空格?,c#,asp.net-mvc,razor,string-formatting,C#,Asp.net Mvc,Razor,String Formatting,我想在两者之间增加更多的空间 @String.Format("AED {0:0,0}", item.Price) <pre>@String.Format("{0,-6} {1:0,0}", "AED", item.Price)</pre> .price { white-space:pre; /* or pre-wrap to enable wrapping */ } 我得到AED 2999(只有一个空格) 我想要AED 2999 在你们的帮助下

我想在两者之间增加更多的空间

 @String.Format("AED       {0:0,0}", item.Price)
<pre>@String.Format("{0,-6} {1:0,0}", "AED", item.Price)</pre>
.price {
    white-space:pre; /* or pre-wrap to enable wrapping */
}
我得到AED 2999(只有一个空格)

我想要AED 2999

在你们的帮助下找到了答案,谢谢各位

 <div style="float: right; font-weight: initial; color: Red; float: right; margin-right: 5px">
    Price -&nbsp;&nbsp;<div style="white-space: pre;float:right;">@String.Format("AED    {0:0,0}", item.Price)</div>
 </div><br />

Price-@String.Format(“AED{0:0,0}”,item.Price)


插入unicode空格\x0020或插入制表符\t? 或“pre”标签

标签应能正常工作:

@String.Format(“AED{0:0,0}”,2999)

众所周知,格式化字符串上的多个空格将被解释为单个空格。要使用多个空格(也称为字符串对齐),请使用以下方式:

参考:

(一)

(2) (多个空格应如何使用预格式化标记的原因)


(3) (CSS样式用于设置预格式化的空白)

您需要使用
空白:pre
(例如,
@String.Format(“AED{0:0,0}”,item.Price)
)这取决于你在哪里做,但是看看:和@StephenMuecke我使用的是float right,但是文本拆分和价格显示在Razor视图的下一行中,你只需要使用PRE-Tag
@String.Format(“AED{0:0,0}”,2999)
Why
float:right?你想用这个做什么?它看起来像是
AED
是一个属性的名称,
Price
是它的值,在这种情况下,您不应该尝试这样格式化-使用两个单独的元素。@String.format(“AED\t{0:0,0}”,item.OfferPrice)没有work@String.Format(“AED\x0020\x0020{0:0,0}”,item.OfferPrice)不起作用,但我失去了样式,唯一的颜色是那里你必须添加更多的css代码,使预标记更时尚:)一旦在浏览器中呈现,它将再次折叠:)在输出周围使用标记可以保留返回的字符串。@TetsuyaYamamoto对预标记功能进行了一点调整,使我的一天变得轻松愉快
<span class="price">@String.Format("{0,-6} {1:0,0}", "AED", item.Price)</span>
.price {
    white-space:pre; /* or pre-wrap to enable wrapping */
}