Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 6th, 2006, 12:37 AM
Registered User
 
Join Date: Jan 2006
Location: Singapore, , Singapore.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to fukchai2000
Default string formatter = "{0,22} {1}"; //what it mean?

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

  #2 (permalink)  
Old January 6th, 2006, 08:36 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

.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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting formatter to org.apache.juli.FileHandler aurelije Apache Tomcat 1 January 12th, 2011 06:54 AM
about charBuf.position() and Formatter yuanhuajie BOOK: Beginning Java 2, JDK 5 Edition 0 June 27th, 2006 10:46 AM
Listing 22-6 bpdsmark BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 2 March 26th, 2006 01:29 PM
addhandler catch 22 roog ASP.NET 1.0 and 1.1 Professional 2 February 20th, 2006 01:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.