Equivalent String formats in CSharp

  • Thread starter Thread starter L
  • Start date Start date
L

L

Hi there,

Something like this in C++

String sTmp;
for (int i = 5; i <=15; i++)
{
sTmp.format("%2s", i)
}

would print

5
6
7
8
9
10
11
12
12
14
15

I should imitate the same in Csharp. ( Notice the space before the
numbers 5 through 9). Is there a way to do this using String.Format in
Csharp?

Thanks,
Lalasa.
 
string sTmp;
for (int i = 5; i <=15; i++)
{
sTmp = String.Format("{0,2}", i);
}


the values inside the {}s are: the index into the parameters following the
format string, comma, the width of the field it should be placed in (the
width is optional). This can (optionally) also be follwed by a colon and a
format specifier.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top