I need something in c# which work like the setw() in c++

Nina picture Nina · Mar 12, 2012 · Viewed 7.8k times · Source

I am using a richTextBox in c#. I need to display strings of different length inside one richTextBox but these strings should be perfectly aligned.. this is an example..

abcd   abcde  abcde
ab     abc    abcdef

I know how to do this in c++ using the setw function.. but I could not find an equivalent in c#.

Answer

Julien picture Julien · Mar 12, 2012
string varName=String.Format("{0,10:D}", 2);

This will format number 2 as a string of width 10 aligned right, use -5 to have it aligned left in the width of 5...

Source : http://answers.yahoo.com/question/index?qid=20100727164827AAqJ1Hn