Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Online SQL Formatter damaha SQL Language 1 August 14th, 2018 09:35 AM
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



All times are GMT -4. The time now is 06:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.