471,582 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 software developers and data experts.

format string question

MM
Hi,

I have a param class containg these vars:-
string key; // eg: "WN"
object value; // eg: 1.2
string format; // eg "F2"

and I output these to a StreamWriter using

nc_file.Write("{0}{1:" + param.format + "}", param.key, param.value);

to give output like (using above egs) "WN1.20"

This works great for numeric types. Problem is that there are a couple
of string values which require padding - eg: "FN<some filename...."
which requires a fixed field size of say 20.

Is there a way to use a format string to achieve this - if there is I
haven't figured it. 99% of all parameters are string key/ numeric value
and I'm hoping I don't need to use special cases in the enumerator to
catch the few string values that need padding. Hopefully this makes sense.

Thanks for the help. matthew.

Nov 17 '05 #1
2 1485
> This works great for numeric types. Problem is that there are a couple
of string values which require padding - eg: "FN<some filename...."
which requires a fixed field size of say 20.

The following code displays a string with a field size of 10. The first
example is right-padded, the second left padded.

Console.WriteLine( "...{0,10}...", "a" );
Console.WriteLine( "...{0,-10}...", "a" );

Is that what you mean?

Greetings,
Wessel
Nov 17 '05 #2
MM
Wessel Troost wrote:
This works great for numeric types. Problem is that there are a
couple of string values which require padding - eg: "FN<some
filename...." which requires a fixed field size of say 20.

The following code displays a string with a field size of 10. The
first example is right-padded, the second left padded.

Console.WriteLine( "...{0,10}...", "a" );
Console.WriteLine( "...{0,-10}...", "a" );

Is that what you mean?

Greetings,
Wessel


Hi Wessel,

I've been trying Console.WriteLine("...{0:-20}, etc) so that's my
mistake. Thanks alot, matthew.
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by san | last post: by
6 posts views Thread by Stuart McGraw | last post: by
7 posts views Thread by Roger Helliwell | last post: by
7 posts views Thread by Tommy Vercetti | last post: by
16 posts views Thread by Al Reid | last post: by
13 posts views Thread by Roy | last post: by
6 posts views Thread by Scewbedew | last post: by
9 posts views Thread by Martin | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.