Netzwerke

C# Strings formatieren

Storage Area Network C# Strings formatieren Useragents
C# Strings formatieren

//Formatieren von negativen Integr oder Fließkommazahlen:
(Die Ausgabe ist natürlich abhängig von der Ländereinstellung. In diesem Beispiel: english)


Console.WriteLine("Hier die verschiedenen Formate:");


s = String.Format(CultureInfo.InvariantCulture,
"(C) Currency (123.00)
{0:C}\n" +
"(D) Decimal -123
{0:D}\n" +
"(E) Scientific -1.234500E+002
{1:E}\n" +
"(F) Fixed point -123.45
{1:F}\n" +
"(G) General (default) -123
{0:G}\n" +
"(N) Number: -123.00
{0:N}\n" +
"(P) Percent -12,345.00 %
{1:P}\n" +
"(R) Round-trip: -123.45
{1:R}\n" +
"(X) Hexadecimal FFFFFF85 {0:X}\n", -123, -123.45f); Console.WriteLine(s);

// Formatieren von Uhrzeit und Datum in C#

s = String.Format(CultureInfo.InvariantCulture.DateTimeFormat,
"(d) Short date 07/09/2007
{0:d}\n" +
"(D) Long date Monday, 09 July 2007
{0:D}\n" +
"(t) Short time 13:48
{0:t}\n" +
"(T) Long time 13:48:05
{0:T}\n" +
"(f) Full date/short time Monday, 09 July 2007 13:48
{0:f}\n" +
"(F) Full date/long time Monday, 09 July 2007 13:48:05
{0:F}\n" +
"(g) General date/short time 07/09/2007 13:48
{0:g}\n" +
"(G) General date/long time (default):07/09/2007 13:48:05
{0:G}\n" +
"(M) Month July 09
{0:M}\n" +
"(R) RFC1123 Mon, 09 Jul 2007 13:48:05 GMT
{0:R}\n" +
"(s) Sortable 2007-07-09T13:48:05
{0:s}\n" +
"(u) Universal sortable 2007-07-09 13:48:05Z
{0:u} \n" +
"(U) Universal sortable Monday, 09 July 2007 20:48:05
{0:U}\n" +
"(Y) Year: 2007 July {0:Y}\n", thisDate);

Console.WriteLine(s);
}

admin

02/24/08 um 12:35:13