[C#] Formatter

mercoledì 19 novembre 2008 - 13.00

yagamiraito Profilo | Newbie

In C# esiste il corrispettivo della classe java "java.util.Formatter" la quale è

"An interpreter for printf-style format strings. This class provides support for layout justification and alignment, common formats for numeric,
string, and date/time data, and locale-specific output. Common Java types such as byte, BigDecimal, and Calendar are supported.
Limited formatting customization for arbitrary user types is provided through the Formattable interface"

?

alx_81 Profilo | Guru

>In C# esiste il corrispettivo della classe java "java.util.Formatter"?
Secondo me puoi ottenere quello che ti serve con i metodi di formattazione del framework:

Standard Date and Time Format Strings
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx

Custom Date and Time Format Strings
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

CultureInfo Class
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx
--

Alessandro Alpi | SQL Server MVP

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.support.microsoft.com/profile/Alessandro.Alpi
http://italy.mvps.org

yagamiraito Profilo | Newbie

Purtroppo al momento non ho la possibilità di verificare se quello che ho pensato è corretto:

Java Code:
Locale locale = null; DateFormat dataFormato = null; public A(Locale locale, long e, Formatter f) { this.locale = locale; this.dataFormato = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, locale); String data = dataFormato.format(new Date(e)); f.format(locale, "<%s tempo=\"%s\">\n", e, data); }


in C# diventerebbe così?
Culturenfo locale = null; DateTimeFormatInfo dataFormato = null; public A(CultureInfo locale,long e) { this.locale = locale; dataFormato = (new CultureInfo("it-IT")).DateTimeFormat; string data = new DateTime(e).ToString(dataFormato); String.Format(data,dataFormato); }


O sono completamente fuori strada?

alx_81 Profilo | Guru

Ti consiglio di pubblicarlo in un nuovo thread.. perchè non saprei aiutarti.
--

Alessandro Alpi | SQL Server MVP

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.support.microsoft.com/profile/Alessandro.Alpi
http://italy.mvps.org
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5