How to get the number of characters of a tab in .NET?
Is there a way to get the length (number of characters/blanks) of a tab in .NET? I am writing data t开发者_C百科o a text file and would like to create a table with two columns. Since some column entries in the first column appear to be longer/shorter than others, the second column looks ugly. I tried inserting a couple of \t's between entries, but that didn't fully help.
You can use spaces instead of tabs to format your data neatly in an ASCII table.
The string.PadLeft
and string.PadRight
methods may help you.
Tab width is determined by the program the shows it, there isn't a fixed number. You can easily pad with spaces when writing the file, a string's format supports that:
String.Format("{0,-16}", "String"); // align left
String.Format("{0,16}", "String"); // align right
Example: http://ideone.com/B4VvC
There is no fixed number of positions for a TAB. Most editors allow you to specify that number.
精彩评论