|
Subject:
|
string formatter = "{0,22} {1}"; //what it mean?
|
|
Posted By:
|
fukchai2000
|
Post Date:
|
1/5/2006 11:37:52 PM
|
Hi guys,
I got this piece of code from msdn, the thing that i don't understand is string formatter = "{0,22} {1}"; ---> what actually the {0,22} for? NumberFormatInfo provider = new NumberFormatInfo( ); string formatter = "{0,22} {1}";
int Int32A = -252645135;
Console.WriteLine( formatter, "Default", "Format Provider" ); Console.WriteLine( formatter, "-------", "---------------" );
Console.WriteLine( formatter, Convert.ToString( Int32A ), Convert.ToString( Int32A, provider ) ); print out: Default Format Provider ------- --------------- 252645135 252645135
can somebody explain to me please. (since i'm quite new to c#)
Thanks in advance
|
|
Reply By:
|
planoie
|
Reply Date:
|
1/6/2006 7:36:15 AM
|
.NET supports formatting strings. Each {x} token represents a value to be replaced and formatted. For example:
String.Format("My name is {0}", "Peter")
results in "My name is Peter"
You can extend how each token behaves by putting formatting information after the the token indexer:
String.Format("Today is {0,mm/DD/yyyy}", Date.Today)
results in "Today is 01/06/2006" (that formatting string may not be exactly correct, just to give you the idea)
In your example, I don't know off hand what 22 does. Look up formatting on MSDN and you'll find many pages about building formatting strings for dates, numbers, etc.
-Peter
|
|