M
MC
Is it possible to use String.Format and a format specifier in such a
way to ensure that a string does not exceed the field width in which
it is placed?
Example:
string [] strings = {"Hello World", "Wednesday Evening", "Hi"};
string output;
foreach(string str in strings)
{
output = String.Format("{0,-4:???}", str);
}
The -4 ensures that str is placed into a field width 4 characters
wide, left justified--great!
What does ??? have to be so that str never exceeds 4 characters--so
that the output is:
Hell
Wedn
Hi
This can be done in C with printf(), so I thought it would be possible
in .NET.
Thanks,
Craig
way to ensure that a string does not exceed the field width in which
it is placed?
Example:
string [] strings = {"Hello World", "Wednesday Evening", "Hi"};
string output;
foreach(string str in strings)
{
output = String.Format("{0,-4:???}", str);
}
The -4 ensures that str is placed into a field width 4 characters
wide, left justified--great!
What does ??? have to be so that str never exceeds 4 characters--so
that the output is:
Hell
Wedn
Hi
This can be done in C with printf(), so I thought it would be possible
in .NET.
Thanks,
Craig