Search This Blog

Friday, February 20, 2009

String and String Formatting

Inm Asp.Net framework format inline string expressions, including String.Format[^], StringBuilder.AppendFormat[^], and TextWriter.Write[^] (and WriteLine[^]), which the Console[^] class inherits


DateTime String Formatting :

DateTime now = DateTime.Now;
string.Format("Short date: {0:d}", now);
string.Format("Long date: {0:D}", now);
string.Format("Sortable date/time: {0:s}", now);
string.Format("Custom date: {0:ddd, MMM dd, yyyy}", now);

Currency String Formatting($3.00) :

Currency:     String.Format("{0:C}", <>);
Decimal: String.Format("{0:C}", <>);
Scientific: String.Format("{1:E}", <>);
Fixed point: String.Format("{1:F}", <>);
General:. String.Format("{0:G}", <>);
Number: String.Format("{0:N}", <>);
Percent:. String.Format("{1:P}", <>);
Round-trip: String.Format("{1:R}", <>);
Hexadecimal: String.Format("{0:X}", <>);








No comments: