Reputation: 8038
I have a line of code in my application that writes some string values to an XmlElement and applies some padding using string formating.
string.Format("{0:-10}{1:-10}{2:-10}", i.Department, i.Category, i.Item)
The outcome for this should be a 30 character string with the Department, Category and Item values.
So this works on our server but not on my local machine. What would cause this to stop working?
Upvotes: 0
Views: 1650
Reputation: 47510
These ways will work safely in any environment.
string.Format("{0}:-10{1}:-10{2}:-10", i.Department, i.Category, i.Item, ":-")
OR
string.Format("{0}{3}{1}{3}{2}{3}", i.Department, i.Category, i.Item, ":-10")
If you are going to do padding do as below. Have a look here for more details on padding formats.
string.Format("{0}{3,-10}{1}{3,-10}{2} {3,-10}", i.Department, i.Category, i.Item, ":")
Upvotes: 0
Reputation: 93030
Use , instead of : - that's the correct syntax:
string.Format("{0,-10}{1,-10}{2,-10}", i.Department, i.Category, i.Item)
Upvotes: 5