mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-28 05:33:48 -08:00
C# port of MathDice
This commit is contained in:
15
61 Math Dice/csharp/StringExtensions.cs
Normal file
15
61 Math Dice/csharp/StringExtensions.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace MathDice
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
private const int ConsoleWidth = 120; // default console width
|
||||
|
||||
public static string CentreAlign(this string value)
|
||||
{
|
||||
int spaces = ConsoleWidth - value.Length;
|
||||
int leftPadding = spaces / 2 + value.Length;
|
||||
|
||||
return value.PadLeft(leftPadding).PadRight(ConsoleWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user