Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
C# Programming

Formatting Strings and Numbers

 

Input and Output

Formatting Strings and Numbers
We can format output involving fixed and variable components. Usually we align strings to the left and numebrs to the right.

1. [ C# ]


Big

In the Write a number of values may follow the format string. These values are used up by {0}, {1} placeholders in the format string.

The format string is

"Country: {0:-18} GDP: {1,20:n0}\n"

{0:-18}
the minus in -18 means align left, the 18 means 18 characters are to be used.
{1,20:n0}
The 20 means use 20 characters and align right, d is for decimal, the n0 means include , separator every three digits and give zero decimal places.
\n
This starts a new line.