.

String.Format

can use "string.Format" like below,<br /><pre class="brush: c-sharp;">int k=16;
string x = string.Format(" '{0,-8}'",k);
Console.WriteLine(x);

or like below using a shortend version “Console.WriteLine“:

int k=16;
Console.WriteLine(" '{0,-8}'",k); // produces: '16 '
Console.WriteLine(" '{0,8}'",k); // produces: ' 16'
Console.WriteLine(" '{0:X}'",k); //(in HEX) produces: '10'
Console.WriteLine(" '{0:X10}'",k); //(in HEX) produces:'0000000010'
Console.WriteLine( 1234567.ToString("#,##0")); // writes with commas: 1,234,567
Console.WriteLine("Completion Ratio: {0:##.#}%",100.0*46/55); // 'Completion Ratio: 83.6%'

double myDouble = 1.234567;
Console.WriteLine(myDouble.ToString("#.###")); // '1.234'

What's your thoughts on this?

*

Protected by WP Anti Spam