Why does string.format("{0:-10}") give off different results on different PCs
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?
Use , instead of : - that's the correct syntax:
string.Format("{0,-10}{1,-10}{2,-10}", i.Department, i.Category, i.Item)
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, ":")
精彩评论