String.Format("{0}", "formatting string"};


//Uses the "en-US" culture.
 enum Color {Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;

//Format the strings
s=String.Format(
"String: {0,10} \n"+ // Test
"String: {0,-10} \n","Test"); // Test 

//Format the numbers in various ways.(or c\d\e\f\g\n\p\r\x)
s = String.Format(
"(C) Currency: . . . . . . . . . . . . . . {0:C}\n" + //$123.00
"(D) Decimal: . . . . . . . . . . . . . . . {0:D}\n" + //-123
"(D) Decimal: . . . . . . . . . . . . . . . {0:D5}\n" + //-00123
"(D) Decimal: . . . . . . . . . . . . . . . {1:D}\n" + //System.FormatException
"(E) Scientific: . . . . . . . . . . . . . . {1:E}\n" + //-1.234500E+002
"(F) Fixed point: . . . . . . . . . . . . . {1:F}\n" + //-123.45
"(F) Fixed point: . . . . . . . . . . . . . {1:F0}\n" + //-123
"(G) General: . . . . . . .. . . . . . . . {0:G}\n" + //-123
"(default= 'G'): . . . . . . . . . . . . . . . {0}\n" + //-123
"(N) Number: . . . . . . . . . . . . . . .{0:N}\n" + //-123.00
"(N) Number: . . . . . . . . . . . . . . {0:N1}\n" + //-123.0
"(P) Percent: . . . . . . . . . . . . . . .{1:P}\n" + //-12,345.00%
"(R) Round-trip: . . . . . . . . . . . . .{1:R}\n" + //-123.45
"(X) Hexadecimal: {0:X}\n", -123, -123.45f); //FFFFFF85


//Custom number formatting
s = String.Format(
"(0) Placeholder: . . . . . . . . . . . . . . {0:00.000}\n" + //-1234.560
"(#) Placeholder: . . . . . . . . . . . . . .{0:#.##}\n" + //-1234.56
"(.) Placeholder: . . . . . . . . . . . . . . {0:0.0}\n" + //-1234.6
"(,) Seperator: . . . . . . . . . . . . . . . {0:0,0}\n" + //-1,234
"(%) Percentage: . . . . . . . . . . . . . {0:0%}\n", -1234.56); //123456%
// Format the current date in various ways.
s = String.Format(
"(d) Short date: . . . . .{0:d}\n" + //4/17/2007
"(D) Long date:. . . . . .{0:D}\n" + //Saturday, April 17, 2007
"(t) Short time:. . . . . . {0:t}\n" + //10:11 PM
"(T) Long time: . . . . . {0:T}\n" + //10:11:04 PM
"(f) Full date/short time:{0:f}\n" + //Saturday, April 17, 2007 10:11 PM
"(F) Full date/long time:{0:F}\n" + //Saturday, April 17, 2007 10:11:04 PM
"(g) General d/s time: . {0:g}\n" + //4/17/2007 10:11 PM
"(G) General dl time: . . {0:G}\n" + //4/17/2007 10:11:04 PM
" (default='G'):. . . . . . {0}\n" + //4/17/2007 10:11:04 PM
"(M) Month:. . . . . . . . {0:M}\n" + //April 17
"(R) RFC1123:. . . . . . .{0:R}\n" + //Tues, 17 Apr 2004 22:11:04 GMT
"(s) Sortable: . . . . . . .{0:s}\n" + //2007-04-17T22:11:04
"(u) Universal sortable: {0:u}\n" + //2007-04-17 22:11:04Z
"(U) Universal sortable: {0:U}\n" + //Tuesday, April 17, 2007 10:11:04 PM
"(Y) Year: . . {0:Y}\n", thisDate); //April, 2007
//Custom date formatting
s = String.Format(
"(dd) Day: . . . . . . . . . . . . . . . .{0:dd}\n" + //17
"(ddd) Short day name:. . . . . . .{0:ddd}\n" + //Tues.
"(dddd) Full day name:. . . . . . {0:dddd}\n" + //Tuesday
"(hh) 2 digit hour: . . . . . . . . . .{0:hh}\n" + //10
"(HH) 2 digit hour(24 hour): . . . .{0:HH}\n" + //22
"(mm) 2 digit minute: . . . . . . . .{0:mm}\n" + //39
"(MM) Month: . . . . . . . . . . . . .{0:MM}\n" + //04
"(MMM) Short month name: . . {0:MMM}\n" + //Apr.
"(MMMM) Month name:. . . . .{0:MMMM}\n" + //April
"(ss) Seconds:. . . . . . . . . . . . .{0:ss}\n" + //48
"(tt) AM/PM:. . . . . . . . . . . . . . {0:tt}\n" + //PM
"(yy) 2 digit year: . . . . . . . . . .{0:yy}\n" + //07
"(yyyy) 4 digit year: . . . . . . {0:yyyy}\n" + //2007
"(:) Seperator: . . . . . . {0:hh:mm:ss}\n" + //22:39:48
"(/) Seperator:{0:dd/MM/yyyy}\n", "April 17, 2007 22:39:48");//17/04/2007
// Format a Color enumeration value in various ways.
s = String.Format(
"(G) General:. . . . . . . . . . . . {0:G}\n" + //Green
"(default = 'G'):. . . . . . . . . . . . {0}\n" + //Green
"(F) Flags (flags or integer):. . {0:F}\n" + //Green
"(D) Decimal number: . . . . . . {0:D}\n" + //3
"(X) Hexadecimal:{0:X}\n", Color.Green); //00000003
|