Odd variable length format specifier question.

  • Thread starter Thread starter TonyM
  • Start date Start date
T

TonyM

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",iIndentLevel,"
",pFunctionStringTable[sTraceData.usFunctionNum]);


Thanks alot for any and all help!
-Tony
 
...
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",iIndentLevel,"
",pFunctionStringTable[sTraceData.usFunctionNum]);

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

string buff =
"Entering: " +
pFunctionStringTable[sTraceData.usFunctionNum].PadLeft(iIndentLevel) +
"\r\n";

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

string buff = new string(' ', iIndentLevel) +
pFunctionStringTable[sTraceData.usFunctionNum];

--Liam.
 
Back
Top