/*
* Copyright (c) United Binary LLC. All rights reserved.
*
* This code is licensed under the MIT License
*
* SEE: http://harnessit.codeplex.com/license
*
*/
#region using ...
using System;
using System.Text;
#endregion
namespace UnitedBinary.Core.Utility.Text
{
///
public sealed class Format
{
private Format() {}
///
public static string PadString(string text, char padChar, int length, bool padFromFront)
{
if (length <= 0)
{
throw new ArgumentException("Length must be positive.", "length");
}
if (text == null)
{
text = string.Empty;
}
StringBuilder sb = new StringBuilder(length);
if (padFromFront)
{
int currentLength = 0;
int padsNeeded = length - text.Length;
while (currentLength < padsNeeded)
{
currentLength++;
sb.Append(padChar);
}
sb.Append(text);
}
else
{
sb.Append(text);
int currentLength = text.Length;
while (currentLength < length)
{
currentLength++;
sb.Append(padChar);
}
}
string paddedString = sb.ToString();
return paddedString;
}
}
}