String.Format with a variable field width

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



In C, printf allows us to specify a runtime (non-constant) field width
of a formatted value by using the * character. Is there something
like that for System.String.Format? In C#, I find myself having to
use concatenation, which is awkward to write and to read:

s.Format("{0," + fieldWidth.ToString() + "}", val);

Preferably, I'd like to nest two placeholders, like this:

s.Format("{0,{1}}", val, fieldWidth);

but it doesn't like that (Framework 2.0).

Is currently available somehow? I didn't see it in MSDN. If not, was
there never any noise about the lack of it in Framework 1.x?? And are
there any plans to add it in the near future?

Thanks,
Craig
.



Relevant Pages

  • Re: Setting Primary Key in DataTable
    ... > framework. ... > an array of datacolumns and then specify True for the primary key. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Term Rewriting vs. Functional Programming
    ... BTW it would be possible to formalise tail call optimisation, though probably outside of the framework used for the rest of the language semantics. ... Specify a program that ... Add the specification that this program must run to completion without throwing exceptions or crashing, under all memory configurations that the compiler can emit code for. ...
    (comp.lang.functional)
  • Specifying 1.1 or 2.0
    ... Is it possible to specify which version of the framework should be used ... without going through the IIS config tool? ... http://webpageworkshop.co.uk -- FREE Web tutorials and references ...
    (microsoft.public.dotnet.general)
  • IIS forcing app to use .Net 2.0 when 1.1 is specified
    ... the IIS Manager to specify which framework version a given application ... specifying in IIS Manager that it should use the 1.1. ... Configuration Error ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: String.Format with a variable field width
    ... Buddy Home ... of a formatted value by using the * character. ... use concatenation, which is awkward to write and to read: ... but it doesn't like that (Framework 2.0). ...
    (microsoft.public.dotnet.general)