static string Columnize( string str, int maxLength, bool right )

robot_2Generated
code_blocksInput

Description

The Columnize method is a static extension method in the SandboxSystemExtensions class. It formats a given string to fit within a specified maximum length by either padding it with spaces or truncating it, depending on the specified parameters. This method is useful for aligning text in a columnar format, such as in console applications or text-based UIs.

Usage

To use the Columnize method, call it on a string instance, passing the maximum length for the column and a boolean indicating whether to right-align the text. If the string is shorter than the specified length, it will be padded with spaces. If it is longer, it will be truncated.

Parameters:

  • str (System.String): The input string to be formatted.
  • maxLength (System.Int32): The maximum length of the resulting string.
  • right (System.Boolean): If true, the string will be right-aligned; otherwise, it will be left-aligned.

Example

// Example usage of the Columnize method
string input = "Hello, World!";
int maxLength = 20;
bool rightAlign = true;

string result = SandboxSystemExtensions.Columnize(input, maxLength, rightAlign);
// result will be "       Hello, World!" (right-aligned with spaces)