I want to add more space in between
@String.Format("AED {0:0,0}", item.Price)
I get AED 2,999 (Only Single Space)
I want AED 2,999
Found the answer with your help, Thanks Guys
<div style="float: right; font-weight: initial; color: Red; float: right; margin-right: 5px">
Price - <div style="white-space: pre;float:right;">@String.Format("AED {0:0,0}", item.Price)</div>
</div><br />
Insert unicode whitespace \x0020 or insert tab \t? Or "pre" tag.
<pre> Tag should be working:
<pre>@String.Format("AED {0:0,0}", 2999)</pre>

It is already known that multiple spaces on formatted string will interpreted as single whitespace. To use multiple spaces (aka string alignment), use this way:
<pre>@String.Format("{0,-6} {1:0,0}", "AED", item.Price)</pre>
"-6" is an addition from length of indentation (length = 3) with "AED" string (length = 3) and a whitespace as your question stated above, with minus sign indicates left-aligned formatting. Change "-6" with other required length as you wish.
Edit: Preformatted text may retain formatted string with multiple whitespaces.
Edit 2: If you need to retain formatting (i.e. font style, color, etc), use either <p> or <span> tag, then add a CSS class like this way:
HTML
<span class="price">@String.Format("{0,-6} {1:0,0}", "AED", item.Price)</span>
CSS
.price {
white-space:pre; /* or pre-wrap to enable wrapping */
}
Reference:
(1) http://www.csharp-examples.net/align-string-with-spaces/
(2) https://stackoverflow.com/a/433509 (reason how multiple spaces should use preformatted tag)
(3) https://stackoverflow.com/a/4503044 (CSS style to set preformatted whitespace)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With