跳到主要內容

發表文章

目前顯示的是 6月, 2009的文章

[.Net] String Formatting in C# VB.net

The text inside the curly braces is { index [, alignment ][: formatString ]} . If alignment is positive, the text is right-aligned in a field the given number of spaces; if it’s negative, it’s left-aligned. Strings There really isn’t any formatting within a string, beyond it’s alignment. Alignment works for any argument being printed in a String.Format call. Sample Generates String.Format(”->{1,10}<-”, “Hello”); -> Hello<- String.Format(”->{1,-10}<-”, “Hello”); ->Hello <- Numbers Basic number formatting specifiers: Specifier Type Format Output (Passed Double 1.42) Output (Passed Int -12400) c Currency {0:c} $1.42 -$12,400 d Decimal (Whole number) {0:d} System.FormatException -12400 e Scientific {0:e} 1.420000e+000 -1.240000e+004 f Fixed point {0:f} 1.42 -12400.00 g General {0:g} 1.42 -12400 n Number with commas for thousands {0:n} 1.42 -12,400 r Round trippable {0:r} 1.42 Sy