I learned something new, it seems! As some of the others have said, you can accomplish the same thing using String.Format .
The interpolation strings used in String.Format may also include an optional alignment component.
// index alignment // vv String.Format("Hello {0,-10}!", "World");
If this is negative, the line is left-aligned. When it is positive, it is aligned to the right. In both cases, the line is filled with a space, respectively, if it is shorter than the specified width (otherwise the line is just completely inserted).
I believe this is a simpler and clearer method than having to mess with String.PadRight .
You can also use String.PadRight (or String.PadLeft ). Example:
class Stats { // Contains properties as you defined ... } var stats = new Stats(...); int leftColWidth = 16; int rightColWidth = 13; var sb = new StringBuilder(); sb.AppendLine("=----------------------------------="); sb.Append("= "); sb.Append(("Strength: " + stats.Strength.ToString()).PadRight(leftColWidth)); sb.Append(" | "); sb.Append(("Agility: " + stats.Agility.ToString()).PadRight(rightColWidth)); // And so on.
source share