Odd variable length format specifier question.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TonyM

    Odd variable length format specifier question.

    Hi,
    Can someone help me convert the following C code to the C# equivelent?
    Basically, we're trying to use a variable (iIndentLevel) to change the
    number of spaces in the string.

    sprintf(buff,"% *sEntering: %s\r\n",iIndent Level,"
    ",pFunctionStri ngTable[sTraceData.usFu nctionNum]);


    Thanks alot for any and all help!
    -Tony


  • Bjorn Abelli

    #2
    Re: Odd variable length format specifier question.


    "TonyM" wrote...
    [color=blue]
    > Can someone help me convert the following C code to the C# equivelent?
    > Basically, we're trying to use a variable (iIndentLevel) to change the
    > number of spaces in the string.
    >
    > sprintf(buff,"% *sEntering: %s\r\n",iIndent Level,"
    > ",pFunctionStri ngTable[sTraceData.usFu nctionNum]);[/color]

    Just an example, there are probably other and better solutions...

    string buff =
    "Entering: " +
    pFunctionString Table[sTraceData.usFu nctionNum].PadLeft(iInden tLevel) +
    "\r\n";

    // Bjorn A



    Comment

    • Liam McNamara

      #3
      Re: Odd variable length format specifier question.

      You could just create a new string with iIndentLevel number of spaces and
      add the other string to it:

      string buff = new string(' ', iIndentLevel) +
      pFunctionString Table[sTraceData.usFu nctionNum];

      --Liam.

      "TonyM" <spamsucks@bite me.net> wrote in message
      news:n7Uhd.4375 356$6p.722350@n ews.easynews.co m...[color=blue]
      > Hi,
      > Can someone help me convert the following C code to the C# equivelent?
      > Basically, we're trying to use a variable (iIndentLevel) to change the
      > number of spaces in the string.
      >
      > sprintf(buff,"% *sEntering: %s\r\n",iIndent Level,"
      > ",pFunctionStri ngTable[sTraceData.usFu nctionNum]);
      >
      >
      > Thanks alot for any and all help!
      > -Tony
      >
      >[/color]


      Comment

      Working...