Re: Format String

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 03/17/04


Date: Wed, 17 Mar 2004 08:40:28 -0500


    One solution (and I'm not claiming it is the best, it does have it's
caveats) would be to create the format string dynamically as needed. This
would probably mean cycling through the structure twice, once to find the
max values in each column, another to write the string out in the
appropriate format.

    What I would do is store the information about the max string length for
each column in an array. The array would basically have the same number of
elements as there are rows. Each element in the array would be an index to
the number of the row. The first element in the array would have the
smallest sized value, the next would have next largest value, and so on, and
so on. When you add a new row, you have to insert a new element into this
array (and in the right place) for each column. When you delete a column,
you have to remove the element. When you edit a column, you have to change
the location of the element in the array.

    When you have to write this information out, creating the format string
is then easy, you just take the values from the last element of each array
that corresponds to the column, and then use that for the precision.

    Hope this helps.

-- 
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com
"PawelR" <anonymouse@microsofcik.com> wrote in message
news:ebBVVKBDEHA.712@tk2msftngp13.phx.gbl...
> Hello Group,
> In my apps I formating string:
>     String.Format("{0,-15}{1,-10}{2,-25}{3,-25}",myTable)
> How change width column in code.
> Column width must be more that length string in table.
> I know how is max length string in myTable.
>
> this code is incorect
> int a = -15;
> String.Format("{0,-a}{1,-10}{2,-25}{3,-25}",myTable)
> Error: incorect string format
>
>
> Thx PawelR
>
>


Relevant Pages

  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Structures conversion from C++ to VB-2008
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)