By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,651 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

Equivalent String formats in CSharp

P: n/a
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.

Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
"L" <la********@investors.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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.

Nov 16 '05 #2

P: n/a
L
Thanks a lot.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.